Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
877ffb96
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
877ffb96
编写于
11月 25, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:memory leak
上级
385c49aa
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
46 deletion
+22
-46
source/client/src/clientSml.c
source/client/src/clientSml.c
+22
-46
未找到文件。
source/client/src/clientSml.c
浏览文件 @
877ffb96
...
...
@@ -179,6 +179,8 @@ typedef struct {
SSmlMsgBuf
msgBuf
;
SHashObj
*
dumplicateKey
;
// for dumplicate key
SArray
*
colsContainer
;
// for cols parse, if dataFormat == false
cJSON
*
root
;
// for parse json
}
SSmlHandle
;
//=================================================================================================
...
...
@@ -1317,10 +1319,6 @@ static void smlDestroyTableInfo(SSmlHandle *info, SSmlTableInfo *tag) {
SArray
*
kvArray
=
(
SArray
*
)
taosArrayGetP
(
tag
->
cols
,
i
);
for
(
int
j
=
0
;
j
<
taosArrayGetSize
(
kvArray
);
++
j
)
{
SSmlKv
*
p
=
(
SSmlKv
*
)
taosArrayGetP
(
kvArray
,
j
);
if
(
info
->
protocol
==
TSDB_SML_JSON_PROTOCOL
&&
(
p
->
type
==
TSDB_DATA_TYPE_NCHAR
||
p
->
type
==
TSDB_DATA_TYPE_BINARY
))
{
taosMemoryFree
((
void
*
)
p
->
value
);
}
taosMemoryFree
(
p
);
}
taosArrayDestroy
(
kvArray
);
...
...
@@ -1338,17 +1336,8 @@ static void smlDestroyTableInfo(SSmlHandle *info, SSmlTableInfo *tag) {
}
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
tag
->
tags
);
i
++
)
{
SSmlKv
*
p
=
(
SSmlKv
*
)
taosArrayGetP
(
tag
->
tags
,
i
);
if
(
info
->
protocol
==
TSDB_SML_JSON_PROTOCOL
)
{
taosMemoryFree
((
void
*
)
p
->
key
);
if
(
p
->
type
==
TSDB_DATA_TYPE_NCHAR
||
p
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
taosMemoryFree
((
void
*
)
p
->
value
);
}
}
taosMemoryFree
(
p
);
}
if
(
info
->
protocol
==
TSDB_SML_JSON_PROTOCOL
&&
tag
->
sTableName
)
{
taosMemoryFree
((
void
*
)
tag
->
sTableName
);
}
taosArrayDestroy
(
tag
->
cols
);
taosArrayDestroy
(
tag
->
tags
);
taosMemoryFree
(
tag
);
...
...
@@ -1472,14 +1461,10 @@ static void smlDestroySTableMeta(SSmlSTableMeta *meta) {
taosMemoryFree
(
meta
);
}
static
void
smlDestroyCols
(
SArray
*
cols
,
SMLProtocolType
protocol
)
{
static
void
smlDestroyCols
(
SArray
*
cols
)
{
if
(
!
cols
)
return
;
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
cols
);
++
i
)
{
SSmlKv
*
kv
=
taosArrayGetP
(
cols
,
i
);
if
(
protocol
==
TSDB_SML_JSON_PROTOCOL
&&
kv
!=
NULL
&&
IS_STR_DATA_TYPE
(
kv
->
type
)){
taosMemoryFree
((
void
*
)
kv
->
value
);
}
void
*
kv
=
taosArrayGetP
(
cols
,
i
);
taosMemoryFree
(
kv
);
}
}
...
...
@@ -1512,6 +1497,8 @@ static void smlDestroyInfo(SSmlHandle *info) {
taosArrayDestroy
(
info
->
colsContainer
);
}
destroyRequest
(
info
->
pRequest
);
cJSON_Delete
(
info
->
root
);
taosMemoryFreeClear
(
info
);
}
...
...
@@ -1587,16 +1574,6 @@ cleanup:
}
/************* TSDB_SML_JSON_PROTOCOL function start **************/
static
int32_t
smlJsonCreateSring
(
const
char
**
output
,
char
*
input
,
int32_t
inputLen
)
{
*
output
=
(
const
char
*
)
taosMemoryCalloc
(
1
,
inputLen
);
if
(
*
output
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
memcpy
((
void
*
)(
*
output
),
input
,
inputLen
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
smlParseMetricFromJSON
(
SSmlHandle
*
info
,
cJSON
*
root
,
SSmlTableInfo
*
tinfo
)
{
cJSON
*
metric
=
cJSON_GetObjectItem
(
root
,
"metric"
);
if
(
!
cJSON_IsString
(
metric
))
{
...
...
@@ -1609,7 +1586,8 @@ static int32_t smlParseMetricFromJSON(SSmlHandle *info, cJSON *root, SSmlTableIn
return
TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH
;
}
return
smlJsonCreateSring
(
&
tinfo
->
sTableName
,
metric
->
valuestring
,
tinfo
->
sTableNameLen
);
tinfo
->
sTableName
=
metric
->
valuestring
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
smlParseTSFromJSONObj
(
SSmlHandle
*
info
,
cJSON
*
root
,
int64_t
*
tsVal
)
{
...
...
@@ -1861,7 +1839,8 @@ static int32_t smlConvertJSONString(SSmlKv *pVal, char *typeStr, cJSON *value) {
return
TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN
;
}
return
smlJsonCreateSring
(
&
pVal
->
value
,
value
->
valuestring
,
pVal
->
length
);
pVal
->
value
=
value
->
valuestring
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
smlParseValueFromJSONObj
(
cJSON
*
root
,
SSmlKv
*
kv
)
{
...
...
@@ -2019,10 +1998,8 @@ static int32_t smlParseTagsFromJSON(cJSON *root, SArray *pKVs, char *childTableN
// key
kv
->
keyLen
=
keyLen
;
ret
=
smlJsonCreateSring
(
&
kv
->
key
,
tag
->
string
,
kv
->
keyLen
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
kv
->
key
=
tag
->
string
;
// value
ret
=
smlParseValueFromJSON
(
tag
,
kv
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -2114,7 +2091,7 @@ static int32_t smlParseInfluxLine(SSmlHandle *info, const char *sql, const int l
ret
=
smlParseCols
(
elements
.
cols
,
elements
.
colsLen
,
cols
,
NULL
,
false
,
info
->
dumplicateKey
,
&
info
->
msgBuf
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"SML:0x%"
PRIx64
" smlParseCols parse cloums fields failed"
,
info
->
id
);
smlDestroyCols
(
cols
,
info
->
protocol
);
smlDestroyCols
(
cols
);
if
(
info
->
dataFormat
)
taosArrayDestroy
(
cols
);
return
ret
;
}
...
...
@@ -2126,7 +2103,7 @@ static int32_t smlParseInfluxLine(SSmlHandle *info, const char *sql, const int l
if
(
!
oneTable
)
{
tinfo
=
smlBuildTableInfo
();
if
(
!
tinfo
)
{
smlDestroyCols
(
cols
,
info
->
protocol
);
smlDestroyCols
(
cols
);
if
(
info
->
dataFormat
)
taosArrayDestroy
(
cols
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
...
...
@@ -2218,7 +2195,7 @@ static int32_t smlParseTelnetLine(SSmlHandle *info, void *data, const int len) {
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"SML:0x%"
PRIx64
" smlParseTelnetLine failed"
,
info
->
id
);
smlDestroyTableInfo
(
info
,
tinfo
);
smlDestroyCols
(
cols
,
info
->
protocol
);
smlDestroyCols
(
cols
);
taosArrayDestroy
(
cols
);
return
ret
;
}
...
...
@@ -2226,7 +2203,7 @@ static int32_t smlParseTelnetLine(SSmlHandle *info, void *data, const int len) {
if
(
taosArrayGetSize
(
tinfo
->
tags
)
<=
0
||
taosArrayGetSize
(
tinfo
->
tags
)
>
TSDB_MAX_TAGS
)
{
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"invalidate tags length:[1,128]"
,
NULL
);
smlDestroyTableInfo
(
info
,
tinfo
);
smlDestroyCols
(
cols
,
info
->
protocol
);
smlDestroyCols
(
cols
);
taosArrayDestroy
(
cols
);
return
TSDB_CODE_PAR_INVALID_TAGS_NUM
;
}
...
...
@@ -2282,16 +2259,16 @@ static int32_t smlParseJSON(SSmlHandle *info, char *payload) {
return
TSDB_CODE_TSC_INVALID_JSON
;
}
cJSON
*
root
=
cJSON_Parse
(
payload
);
if
(
root
==
NULL
)
{
info
->
root
=
cJSON_Parse
(
payload
);
if
(
info
->
root
==
NULL
)
{
uError
(
"SML:0x%"
PRIx64
" parse json failed:%s"
,
info
->
id
,
payload
);
return
TSDB_CODE_TSC_INVALID_JSON
;
}
// multiple data points must be sent in JSON array
if
(
cJSON_IsObject
(
root
))
{
if
(
cJSON_IsObject
(
info
->
root
))
{
payloadNum
=
1
;
}
else
if
(
cJSON_IsArray
(
root
))
{
payloadNum
=
cJSON_GetArraySize
(
root
);
}
else
if
(
cJSON_IsArray
(
info
->
root
))
{
payloadNum
=
cJSON_GetArraySize
(
info
->
root
);
}
else
{
uError
(
"SML:0x%"
PRIx64
" Invalid JSON Payload"
,
info
->
id
);
ret
=
TSDB_CODE_TSC_INVALID_JSON
;
...
...
@@ -2299,7 +2276,7 @@ static int32_t smlParseJSON(SSmlHandle *info, char *payload) {
}
for
(
int32_t
i
=
0
;
i
<
payloadNum
;
++
i
)
{
cJSON
*
dataPoint
=
(
payloadNum
==
1
&&
cJSON_IsObject
(
root
))
?
root
:
cJSON_GetArrayItem
(
root
,
i
);
cJSON
*
dataPoint
=
(
payloadNum
==
1
&&
cJSON_IsObject
(
info
->
root
))
?
info
->
root
:
cJSON_GetArrayItem
(
info
->
root
,
i
);
ret
=
smlParseTelnetLine
(
info
,
dataPoint
,
-
1
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"SML:0x%"
PRIx64
" Invalid JSON Payload"
,
info
->
id
);
...
...
@@ -2308,7 +2285,6 @@ static int32_t smlParseJSON(SSmlHandle *info, char *payload) {
}
end:
cJSON_Delete
(
root
);
return
ret
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录