Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c9e176df
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
c9e176df
编写于
8月 06, 2021
作者:
X
xywang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-5784]<fix>: fixed potential memory leak bugs in HTTP module
上级
45cb4333
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
12 deletion
+46
-12
src/plugins/http/src/httpParser.c
src/plugins/http/src/httpParser.c
+34
-8
src/plugins/http/src/httpUtil.c
src/plugins/http/src/httpUtil.c
+12
-4
未找到文件。
src/plugins/http/src/httpParser.c
浏览文件 @
c9e176df
...
@@ -101,13 +101,17 @@ char *httpGetStatusDesc(int32_t statusCode) {
...
@@ -101,13 +101,17 @@ char *httpGetStatusDesc(int32_t statusCode) {
}
}
static
void
httpCleanupString
(
HttpString
*
str
)
{
static
void
httpCleanupString
(
HttpString
*
str
)
{
free
(
str
->
str
);
if
(
str
->
str
)
{
str
->
str
=
NULL
;
free
(
str
->
str
);
str
->
pos
=
0
;
str
->
str
=
NULL
;
str
->
size
=
0
;
str
->
pos
=
0
;
str
->
size
=
0
;
}
}
}
static
int32_t
httpAppendString
(
HttpString
*
str
,
const
char
*
s
,
int32_t
len
)
{
static
int32_t
httpAppendString
(
HttpString
*
str
,
const
char
*
s
,
int32_t
len
)
{
char
*
new_str
=
NULL
;
if
(
str
->
size
==
0
)
{
if
(
str
->
size
==
0
)
{
str
->
pos
=
0
;
str
->
pos
=
0
;
str
->
size
=
len
+
1
;
str
->
size
=
len
+
1
;
...
@@ -115,7 +119,16 @@ static int32_t httpAppendString(HttpString *str, const char *s, int32_t len) {
...
@@ -115,7 +119,16 @@ static int32_t httpAppendString(HttpString *str, const char *s, int32_t len) {
}
else
if
(
str
->
pos
+
len
+
1
>=
str
->
size
)
{
}
else
if
(
str
->
pos
+
len
+
1
>=
str
->
size
)
{
str
->
size
+=
len
;
str
->
size
+=
len
;
str
->
size
*=
4
;
str
->
size
*=
4
;
str
->
str
=
realloc
(
str
->
str
,
str
->
size
);
new_str
=
realloc
(
str
->
str
,
str
->
size
);
if
(
new_str
==
NULL
&&
str
->
str
)
{
// if str->str was not NULL originally,
// the old allocated memory was left unchanged,
// see man 3 realloc
free
(
str
->
str
);
}
str
->
str
=
new_str
;
}
else
{
}
else
{
}
}
...
@@ -317,7 +330,7 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const
...
@@ -317,7 +330,7 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const
static
int32_t
httpOnBody
(
HttpParser
*
parser
,
const
char
*
chunk
,
int32_t
len
)
{
static
int32_t
httpOnBody
(
HttpParser
*
parser
,
const
char
*
chunk
,
int32_t
len
)
{
HttpContext
*
pContext
=
parser
->
pContext
;
HttpContext
*
pContext
=
parser
->
pContext
;
HttpString
*
buf
=
&
parser
->
body
;
HttpString
*
buf
=
&
parser
->
body
;
if
(
parser
->
parseCode
!=
TSDB_CODE_SUCCESS
)
return
-
1
;
if
(
parser
->
parseCode
!=
TSDB_CODE_SUCCESS
)
return
-
1
;
if
(
buf
->
size
<=
0
)
{
if
(
buf
->
size
<=
0
)
{
...
@@ -326,6 +339,7 @@ static int32_t httpOnBody(HttpParser *parser, const char *chunk, int32_t len) {
...
@@ -326,6 +339,7 @@ static int32_t httpOnBody(HttpParser *parser, const char *chunk, int32_t len) {
}
}
int32_t
newSize
=
buf
->
pos
+
len
+
1
;
int32_t
newSize
=
buf
->
pos
+
len
+
1
;
char
*
newStr
=
NULL
;
if
(
newSize
>=
buf
->
size
)
{
if
(
newSize
>=
buf
->
size
)
{
if
(
buf
->
size
>=
HTTP_BUFFER_SIZE
)
{
if
(
buf
->
size
>=
HTTP_BUFFER_SIZE
)
{
httpError
(
"context:%p, fd:%d, failed parse body, exceeding buffer size %d"
,
pContext
,
pContext
->
fd
,
buf
->
size
);
httpError
(
"context:%p, fd:%d, failed parse body, exceeding buffer size %d"
,
pContext
,
pContext
->
fd
,
buf
->
size
);
...
@@ -336,7 +350,12 @@ static int32_t httpOnBody(HttpParser *parser, const char *chunk, int32_t len) {
...
@@ -336,7 +350,12 @@ static int32_t httpOnBody(HttpParser *parser, const char *chunk, int32_t len) {
newSize
=
MAX
(
newSize
,
HTTP_BUFFER_INIT
);
newSize
=
MAX
(
newSize
,
HTTP_BUFFER_INIT
);
newSize
*=
4
;
newSize
*=
4
;
newSize
=
MIN
(
newSize
,
HTTP_BUFFER_SIZE
);
newSize
=
MIN
(
newSize
,
HTTP_BUFFER_SIZE
);
buf
->
str
=
realloc
(
buf
->
str
,
newSize
);
newStr
=
realloc
(
buf
->
str
,
newSize
);
if
(
newStr
==
NULL
&&
buf
->
str
)
{
free
(
buf
->
str
);
}
buf
->
str
=
newStr
;
buf
->
size
=
newSize
;
buf
->
size
=
newSize
;
if
(
buf
->
str
==
NULL
)
{
if
(
buf
->
str
==
NULL
)
{
...
@@ -374,13 +393,20 @@ static HTTP_PARSER_STATE httpTopStack(HttpParser *parser) {
...
@@ -374,13 +393,20 @@ static HTTP_PARSER_STATE httpTopStack(HttpParser *parser) {
static
int32_t
httpPushStack
(
HttpParser
*
parser
,
HTTP_PARSER_STATE
state
)
{
static
int32_t
httpPushStack
(
HttpParser
*
parser
,
HTTP_PARSER_STATE
state
)
{
HttpStack
*
stack
=
&
parser
->
stacks
;
HttpStack
*
stack
=
&
parser
->
stacks
;
int8_t
*
newStacks
=
NULL
;
if
(
stack
->
size
==
0
)
{
if
(
stack
->
size
==
0
)
{
stack
->
pos
=
0
;
stack
->
pos
=
0
;
stack
->
size
=
32
;
stack
->
size
=
32
;
stack
->
stacks
=
malloc
(
stack
->
size
*
sizeof
(
int8_t
));
stack
->
stacks
=
malloc
(
stack
->
size
*
sizeof
(
int8_t
));
}
else
if
(
stack
->
pos
+
1
>
stack
->
size
)
{
}
else
if
(
stack
->
pos
+
1
>
stack
->
size
)
{
stack
->
size
*=
2
;
stack
->
size
*=
2
;
stack
->
stacks
=
realloc
(
stack
->
stacks
,
stack
->
size
*
sizeof
(
int8_t
));
newStacks
=
realloc
(
stack
->
stacks
,
stack
->
size
*
sizeof
(
int8_t
));
if
(
newStacks
==
NULL
&&
stack
->
stacks
)
{
free
(
stack
->
stacks
);
}
stack
->
stacks
=
newStacks
;
}
else
{
}
else
{
}
}
...
...
src/plugins/http/src/httpUtil.c
浏览文件 @
c9e176df
...
@@ -188,13 +188,17 @@ bool httpMallocMultiCmds(HttpContext *pContext, int32_t cmdSize, int32_t bufferS
...
@@ -188,13 +188,17 @@ bool httpMallocMultiCmds(HttpContext *pContext, int32_t cmdSize, int32_t bufferS
bool
httpReMallocMultiCmdsSize
(
HttpContext
*
pContext
,
int32_t
cmdSize
)
{
bool
httpReMallocMultiCmdsSize
(
HttpContext
*
pContext
,
int32_t
cmdSize
)
{
HttpSqlCmds
*
multiCmds
=
pContext
->
multiCmds
;
HttpSqlCmds
*
multiCmds
=
pContext
->
multiCmds
;
if
(
cmdSize
>
HTTP_MAX_CMD_SIZE
)
{
if
(
cmdSize
<=
0
&&
cmdSize
>
HTTP_MAX_CMD_SIZE
)
{
httpError
(
"context:%p, fd:%d, user:%s, mulitcmd size:%d large then %d"
,
pContext
,
pContext
->
fd
,
pContext
->
user
,
httpError
(
"context:%p, fd:%d, user:%s, mulitcmd size:%d large then %d"
,
pContext
,
pContext
->
fd
,
pContext
->
user
,
cmdSize
,
HTTP_MAX_CMD_SIZE
);
cmdSize
,
HTTP_MAX_CMD_SIZE
);
return
false
;
return
false
;
}
}
multiCmds
->
cmds
=
(
HttpSqlCmd
*
)
realloc
(
multiCmds
->
cmds
,
(
size_t
)
cmdSize
*
sizeof
(
HttpSqlCmd
));
HttpSqlCmd
*
new_cmds
=
(
HttpSqlCmd
*
)
realloc
(
multiCmds
->
cmds
,
(
size_t
)
cmdSize
*
sizeof
(
HttpSqlCmd
));
if
(
new_cmds
==
NULL
&&
multiCmds
->
cmds
)
{
free
(
multiCmds
->
cmds
);
}
multiCmds
->
cmds
=
new_cmds
;
if
(
multiCmds
->
cmds
==
NULL
)
{
if
(
multiCmds
->
cmds
==
NULL
)
{
httpError
(
"context:%p, fd:%d, user:%s, malloc cmds:%d error"
,
pContext
,
pContext
->
fd
,
pContext
->
user
,
cmdSize
);
httpError
(
"context:%p, fd:%d, user:%s, malloc cmds:%d error"
,
pContext
,
pContext
->
fd
,
pContext
->
user
,
cmdSize
);
return
false
;
return
false
;
...
@@ -208,13 +212,17 @@ bool httpReMallocMultiCmdsSize(HttpContext *pContext, int32_t cmdSize) {
...
@@ -208,13 +212,17 @@ bool httpReMallocMultiCmdsSize(HttpContext *pContext, int32_t cmdSize) {
bool
httpReMallocMultiCmdsBuffer
(
HttpContext
*
pContext
,
int32_t
bufferSize
)
{
bool
httpReMallocMultiCmdsBuffer
(
HttpContext
*
pContext
,
int32_t
bufferSize
)
{
HttpSqlCmds
*
multiCmds
=
pContext
->
multiCmds
;
HttpSqlCmds
*
multiCmds
=
pContext
->
multiCmds
;
if
(
bufferSize
>
HTTP_MAX_BUFFER_SIZE
)
{
if
(
bufferSize
<=
0
||
bufferSize
>
HTTP_MAX_BUFFER_SIZE
)
{
httpError
(
"context:%p, fd:%d, user:%s, mulitcmd buffer size:%d large then %d"
,
pContext
,
pContext
->
fd
,
httpError
(
"context:%p, fd:%d, user:%s, mulitcmd buffer size:%d large then %d"
,
pContext
,
pContext
->
fd
,
pContext
->
user
,
bufferSize
,
HTTP_MAX_BUFFER_SIZE
);
pContext
->
user
,
bufferSize
,
HTTP_MAX_BUFFER_SIZE
);
return
false
;
return
false
;
}
}
multiCmds
->
buffer
=
(
char
*
)
realloc
(
multiCmds
->
buffer
,
(
size_t
)
bufferSize
);
char
*
new_buffer
=
(
char
*
)
realloc
(
multiCmds
->
buffer
,
(
size_t
)
bufferSize
);
if
(
new_buffer
==
NULL
&&
multiCmds
->
buffer
)
{
free
(
multiCmds
->
buffer
);
}
multiCmds
->
buffer
=
new_buffer
;
if
(
multiCmds
->
buffer
==
NULL
)
{
if
(
multiCmds
->
buffer
==
NULL
)
{
httpError
(
"context:%p, fd:%d, user:%s, malloc buffer:%d error"
,
pContext
,
pContext
->
fd
,
pContext
->
user
,
bufferSize
);
httpError
(
"context:%p, fd:%d, user:%s, malloc buffer:%d error"
,
pContext
,
pContext
->
fd
,
pContext
->
user
,
bufferSize
);
return
false
;
return
false
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录