未验证 提交 3aa24b6b 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Hotfix/sangshuduo/td 3197 taosdemo coverity scan for master (#7375)

* [TD-3197]<fix>: taosdemo and taosdump coverity scan issues.

* exit if read sample file failed.

* fix converity scan issue.

* fix coverity scan issue.

* fix coverity scan memory leak.

* fix resource leak reported by coverity scan.

* fix taosdemo coverity scan issue.
Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
上级 6fe3b30d
...@@ -5820,6 +5820,7 @@ static int32_t prepareStmtBindArrayByType( ...@@ -5820,6 +5820,7 @@ static int32_t prepareStmtBindArrayByType(
} else if (0 == strncasecmp(dataType, } else if (0 == strncasecmp(dataType,
"INT", strlen("INT"))) { "INT", strlen("INT"))) {
int32_t *bind_int = malloc(sizeof(int32_t)); int32_t *bind_int = malloc(sizeof(int32_t));
assert(bind_int);
if (value) { if (value) {
*bind_int = atoi(value); *bind_int = atoi(value);
...@@ -5834,6 +5835,7 @@ static int32_t prepareStmtBindArrayByType( ...@@ -5834,6 +5835,7 @@ static int32_t prepareStmtBindArrayByType(
} else if (0 == strncasecmp(dataType, } else if (0 == strncasecmp(dataType,
"BIGINT", strlen("BIGINT"))) { "BIGINT", strlen("BIGINT"))) {
int64_t *bind_bigint = malloc(sizeof(int64_t)); int64_t *bind_bigint = malloc(sizeof(int64_t));
assert(bind_bigint);
if (value) { if (value) {
*bind_bigint = atoll(value); *bind_bigint = atoll(value);
...@@ -5848,6 +5850,7 @@ static int32_t prepareStmtBindArrayByType( ...@@ -5848,6 +5850,7 @@ static int32_t prepareStmtBindArrayByType(
} else if (0 == strncasecmp(dataType, } else if (0 == strncasecmp(dataType,
"FLOAT", strlen("FLOAT"))) { "FLOAT", strlen("FLOAT"))) {
float *bind_float = malloc(sizeof(float)); float *bind_float = malloc(sizeof(float));
assert(bind_float);
if (value) { if (value) {
*bind_float = (float)atof(value); *bind_float = (float)atof(value);
...@@ -5862,6 +5865,7 @@ static int32_t prepareStmtBindArrayByType( ...@@ -5862,6 +5865,7 @@ static int32_t prepareStmtBindArrayByType(
} else if (0 == strncasecmp(dataType, } else if (0 == strncasecmp(dataType,
"DOUBLE", strlen("DOUBLE"))) { "DOUBLE", strlen("DOUBLE"))) {
double *bind_double = malloc(sizeof(double)); double *bind_double = malloc(sizeof(double));
assert(bind_double);
if (value) { if (value) {
*bind_double = atof(value); *bind_double = atof(value);
...@@ -5876,6 +5880,7 @@ static int32_t prepareStmtBindArrayByType( ...@@ -5876,6 +5880,7 @@ static int32_t prepareStmtBindArrayByType(
} else if (0 == strncasecmp(dataType, } else if (0 == strncasecmp(dataType,
"SMALLINT", strlen("SMALLINT"))) { "SMALLINT", strlen("SMALLINT"))) {
int16_t *bind_smallint = malloc(sizeof(int16_t)); int16_t *bind_smallint = malloc(sizeof(int16_t));
assert(bind_smallint);
if (value) { if (value) {
*bind_smallint = (int16_t)atoi(value); *bind_smallint = (int16_t)atoi(value);
...@@ -5890,6 +5895,7 @@ static int32_t prepareStmtBindArrayByType( ...@@ -5890,6 +5895,7 @@ static int32_t prepareStmtBindArrayByType(
} else if (0 == strncasecmp(dataType, } else if (0 == strncasecmp(dataType,
"TINYINT", strlen("TINYINT"))) { "TINYINT", strlen("TINYINT"))) {
int8_t *bind_tinyint = malloc(sizeof(int8_t)); int8_t *bind_tinyint = malloc(sizeof(int8_t));
assert(bind_tinyint);
if (value) { if (value) {
*bind_tinyint = (int8_t)atoi(value); *bind_tinyint = (int8_t)atoi(value);
...@@ -5904,6 +5910,7 @@ static int32_t prepareStmtBindArrayByType( ...@@ -5904,6 +5910,7 @@ static int32_t prepareStmtBindArrayByType(
} else if (0 == strncasecmp(dataType, } else if (0 == strncasecmp(dataType,
"BOOL", strlen("BOOL"))) { "BOOL", strlen("BOOL"))) {
int8_t *bind_bool = malloc(sizeof(int8_t)); int8_t *bind_bool = malloc(sizeof(int8_t));
assert(bind_bool);
if (value) { if (value) {
if (strncasecmp(value, "true", 4)) { if (strncasecmp(value, "true", 4)) {
...@@ -5923,6 +5930,7 @@ static int32_t prepareStmtBindArrayByType( ...@@ -5923,6 +5930,7 @@ static int32_t prepareStmtBindArrayByType(
} else if (0 == strncasecmp(dataType, } else if (0 == strncasecmp(dataType,
"TIMESTAMP", strlen("TIMESTAMP"))) { "TIMESTAMP", strlen("TIMESTAMP"))) {
int64_t *bind_ts2 = malloc(sizeof(int64_t)); int64_t *bind_ts2 = malloc(sizeof(int64_t));
assert(bind_ts2);
if (value) { if (value) {
if (strchr(value, ':') && strchr(value, '-')) { if (strchr(value, ':') && strchr(value, '-')) {
...@@ -5937,6 +5945,7 @@ static int32_t prepareStmtBindArrayByType( ...@@ -5937,6 +5945,7 @@ static int32_t prepareStmtBindArrayByType(
if (TSDB_CODE_SUCCESS != taosParseTime( if (TSDB_CODE_SUCCESS != taosParseTime(
value, &tmpEpoch, strlen(value), value, &tmpEpoch, strlen(value),
timePrec, 0)) { timePrec, 0)) {
free(bind_ts2);
errorPrint("Input %s, time format error!\n", value); errorPrint("Input %s, time format error!\n", value);
return -1; return -1;
} }
...@@ -6261,7 +6270,7 @@ static int32_t prepareStbStmtBindTag( ...@@ -6261,7 +6270,7 @@ static int32_t prepareStbStmtBindTag(
char *bindBuffer = calloc(1, DOUBLE_BUFF_LEN); // g_args.len_of_binary); char *bindBuffer = calloc(1, DOUBLE_BUFF_LEN); // g_args.len_of_binary);
if (bindBuffer == NULL) { if (bindBuffer == NULL) {
errorPrint("%s() LN%d, Failed to allocate %d bind buffer\n", errorPrint("%s() LN%d, Failed to allocate %d bind buffer\n",
__func__, __LINE__, g_args.len_of_binary); __func__, __LINE__, DOUBLE_BUFF_LEN);
return -1; return -1;
} }
...@@ -6293,7 +6302,7 @@ static int32_t prepareStbStmtBindRand( ...@@ -6293,7 +6302,7 @@ static int32_t prepareStbStmtBindRand(
char *bindBuffer = calloc(1, DOUBLE_BUFF_LEN); // g_args.len_of_binary); char *bindBuffer = calloc(1, DOUBLE_BUFF_LEN); // g_args.len_of_binary);
if (bindBuffer == NULL) { if (bindBuffer == NULL) {
errorPrint("%s() LN%d, Failed to allocate %d bind buffer\n", errorPrint("%s() LN%d, Failed to allocate %d bind buffer\n",
__func__, __LINE__, g_args.len_of_binary); __func__, __LINE__, DOUBLE_BUFF_LEN);
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册