Fix memory leak when adding array elements of basic types.

This commit is contained in:
sunchb 2020-01-06 11:43:51 +08:00
parent 7cb343e85c
commit 2c667176c3
2 changed files with 6 additions and 2 deletions

View File

@ -14,6 +14,8 @@
* to use, or define other parser which conforms to this interface.
* */
#include "stddef.h"
/**
* @brief the type of json object.
*/

View File

@ -144,11 +144,12 @@ int getJsonArray(void* input, const reflect_item_t* tbl, int index, cson_t* obj)
size_t successCount = 0;
for (int i = 0; i < size; i++) {
cson_t jotmp = cson_object();
cson_t jotmp;
if(tbl[index].reflect_tbl[0].field[0] == '0'){ /* field start with '0' mean basic types. */
ret = jsonPackTbl[tbl[index].reflect_tbl[0].type](pSrc + (i * tbl[index].arraySize), tbl[index].reflect_tbl, 0, &jotmp);
}else{
}else{
jotmp = cson_object();
ret = csonStruct2JsonObj(jotmp, pSrc + (i * tbl[index].arraySize), tbl[index].reflect_tbl);
}
@ -156,6 +157,7 @@ int getJsonArray(void* input, const reflect_item_t* tbl, int index, cson_t* obj)
successCount++;
cson_array_add(joArray, jotmp);
} else {
printf("create array item faild.\n");
cson_decref(jotmp);
}
}