Skip to content

Commit

Permalink
Merge pull request #787 from taosdata/fix/TD-30314-3.0
Browse files Browse the repository at this point in the history
fix: coverage fix mem leak
  • Loading branch information
DuanKuanJun authored Aug 23, 2024
2 parents 6ff8d21 + 108c8b1 commit 5070915
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,10 +1265,9 @@ void postFreeResource() {
if (stbInfo->childTblArray) {
for (int64_t child = 0; child < stbInfo->childTblCount;
child++) {
SChildTable *childTbl =
stbInfo->childTblArray[child];
tmfree(childTbl->name);
SChildTable *childTbl = stbInfo->childTblArray[child];
if (childTbl) {
tmfree(childTbl->name);
freeChildTable(childTbl, stbInfo->cols->size);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/benchTmq.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ int buildConsumerAndSubscribe(tmqThreadInfo * pThreadInfo, char* groupId) {
static void* tmqConsume(void* arg) {
tmqThreadInfo* pThreadInfo = (tmqThreadInfo*)arg;
SConsumerInfo* pConsumerInfo = &g_tmqInfo.consumerInfo;
char groupId[16] = {0};

// "sequential" or "parallel"
if (pConsumerInfo->createMode && 0 != strncasecmp(pConsumerInfo->createMode, "sequential", 10)) {

char* tPtr = pConsumerInfo->groupId;
// "share" or "independent"
char groupId[16] = {0};
if (pConsumerInfo->groupMode && 0 != strncasecmp(pConsumerInfo->groupMode, "share", 5)) {

if ((NULL == pConsumerInfo->groupId) || (0 == strlen(pConsumerInfo->groupId))) {
Expand Down Expand Up @@ -310,16 +310,17 @@ int subscribeTestProcess() {
return -1;
}
}
char groupId[16] = {0};
char* tPtr = pConsumerInfo->groupId;

// "share" or "independent"
if (pConsumerInfo->groupMode && 0 == strncasecmp(pConsumerInfo->groupMode, "share", 5)) {
char groupId[16] = {0};
if ((NULL == pConsumerInfo->groupId) || (0 == strlen(pConsumerInfo->groupId))) {
// rand string
memset(groupId, 0, sizeof(groupId));
rand_string(groupId, sizeof(groupId) - 1, 0);
infoPrint("rand generate group id: %s\n", groupId);
pConsumerInfo->groupId = groupId;
tPtr = groupId;
}
}

Expand Down Expand Up @@ -347,7 +348,7 @@ int subscribeTestProcess() {

// "sequential" or "parallel"
if (pConsumerInfo->createMode && 0 == strncasecmp(pConsumerInfo->createMode, "sequential", 10)) {
int retVal = buildConsumerAndSubscribe(pThreadInfo, pConsumerInfo->groupId);
int retVal = buildConsumerAndSubscribe(pThreadInfo, tPtr);
if (0 != retVal) {
infoPrint("%s\n", "buildConsumerAndSubscribe() fail!");
ret = -1;
Expand Down
31 changes: 23 additions & 8 deletions src/taosdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -3546,9 +3546,12 @@ static int dumpCreateTableClauseAvro(

avro_value_set_branch(&value, 1, &branch);
if(g_args.dotReplace) {
char tableName[TSDB_TABLE_NAME_LEN+1];
replaceCopy(tableName, tableDes->name);
avro_value_set_string(&branch, tableName);
char tableName[TSDB_TABLE_NAME_LEN+1] = "";
if(replaceCopy(tableName, tableDes->name)) {
avro_value_set_string(&branch, tableName);
} else {
avro_value_set_string(&branch, tableDes->name);
}
} else {
avro_value_set_string(&branch, tableDes->name);
}
Expand Down Expand Up @@ -4785,6 +4788,8 @@ static int processValueToAvro(
uint16_t u16Temp = 0;
uint32_t u32Temp = 0;
uint64_t u64Temp = 0;
memset(&firsthalf, 0, sizeof(avro_value_t));
memset(&secondhalf, 0, sizeof(avro_value_t));

switch (type) {
case TSDB_DATA_TYPE_BOOL:
Expand Down Expand Up @@ -6278,9 +6283,6 @@ static int64_t dumpInAvroNtbImpl(
} else {
#endif
TAOS_RES *res = taos_query(taos, buf);
if(newBuf) {
free(newBuf);
}
int code = taos_errno(res);
if (0 != code) {
errorPrint("%s() LN%d,"
Expand All @@ -6292,6 +6294,9 @@ static int64_t dumpInAvroNtbImpl(
} else {
success++;
}
if(newBuf) {
free(newBuf);
}
taos_free_result(res);
#ifdef WEBSOCKET
}
Expand Down Expand Up @@ -8986,6 +8991,9 @@ static int createMTableAvroHeadImp(
uint16_t u16Temp = 0;
uint32_t u32Temp = 0;
uint64_t u64Temp = 0;
memset(&firsthalf, 0, sizeof(avro_value_t));
memset(&secondhalf, 0, sizeof(avro_value_t));


int type = subTableDes->cols[subTableDes->columns + tag].type;
switch (type) {
Expand Down Expand Up @@ -9437,7 +9445,11 @@ static int64_t fillTbNameArrNative(
TAOS_RES *res = taos_query(taos, command);
int32_t code = taos_errno(res);
if (code) {
return cleanIfQueryFailed(__func__, __LINE__, command, res);
errorPrint("%s() LN%d, fillTbNameArrNative failed to run command <%s>. "
"code: 0x%08x, reason: %s\n",
__func__, __LINE__, command, taos_errno(res), taos_errstr(res));
taos_free_result(res);
return -1;
}

TAOS_ROW row = NULL;
Expand Down Expand Up @@ -9604,6 +9616,8 @@ static int writeTagsToAvro(
uint16_t u16Temp = 0;
uint32_t u32Temp = 0;
uint64_t u64Temp = 0;
memset(&firsthalf, 0, sizeof(avro_value_t));
memset(&secondhalf, 0, sizeof(avro_value_t));

int type = tbDes->cols[tbDes->columns + tag].type;
switch (type) {
Expand Down Expand Up @@ -11392,8 +11406,9 @@ static void *dumpTablesOfStbThread(void *arg) {
#ifdef WEBSOCKET
}
#endif
if (!g_args.avro) {
if (fp) {
fclose(fp);
fp = NULL;
}

return NULL;
Expand Down

0 comments on commit 5070915

Please sign in to comment.