fixed memory leak

This commit is contained in:
overflowerror 2021-05-04 16:52:15 +02:00
parent 0284446885
commit cb78ffefb3
2 changed files with 13 additions and 4 deletions

View file

@ -120,7 +120,14 @@ jsonValue_t* _json_marshall_value(const char* type, void* value) {
}
}
char* _json_marshall(const char* type, void* value) {
return json_stringify(_json_marshall_value(type, value));
jsonValue_t* json = _json_marshall_value(type, value);
if (json == NULL)
return NULL;
char* result = json_stringify(json);
json_free(json);
return result;
}
static void* json_unmarshall_char(jsonValue_t* value) {
@ -271,7 +278,7 @@ void* _json_unmarshall(const char* type, const char* json) {
}
void* tmp = _json_unmarshall_value(type, value);
free(value);
json_free(value);
return tmp;
}

View file

@ -110,11 +110,13 @@ char* generateUnmarshallFunction(FILE* output, struct structinfo* info, char* su
fprintf(output, "\tif (d == NULL)\n");
fprintf(output, "\t\treturn NULL;\n");
fprintf(output, "\tvoid* tmp;\n");
fprintf(output, "\tjsonValue_t* tmpValue;\n");
for (size_t i = 0; i < info->memberno; i++) {
struct memberinfo* member = info->members[i];
fprintf(output, "\ttmp = _json_unmarshall_value(\"%s\", json_object_get(v, \"%s\"));\n", member->type->type, member->name);
fprintf(output, "\ttmpValue = json_object_get(v, \"%s\");\n", member->name);
fprintf(output, "\ttmp = _json_unmarshall_value(\"%s\", tmpValue);\n", member->type->type);
fprintf(output, "\tjson_free(tmpValue);\n");
if (strcmp(member->type->type, "string") == 0) {
fprintf(output, "\td->%s = (char*) tmp;\n", member->name);
} else if (member->type->isPointer) {