mirror of
https://github.com/sigmasternchen/libargo
synced 2025-03-15 21:28:54 +00:00
fixed memory leak
This commit is contained in:
parent
0284446885
commit
cb78ffefb3
2 changed files with 13 additions and 4 deletions
|
@ -120,7 +120,14 @@ jsonValue_t* _json_marshall_value(const char* type, void* value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char* _json_marshall(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) {
|
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);
|
void* tmp = _json_unmarshall_value(type, value);
|
||||||
free(value);
|
json_free(value);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,11 +110,13 @@ char* generateUnmarshallFunction(FILE* output, struct structinfo* info, char* su
|
||||||
fprintf(output, "\tif (d == NULL)\n");
|
fprintf(output, "\tif (d == NULL)\n");
|
||||||
fprintf(output, "\t\treturn NULL;\n");
|
fprintf(output, "\t\treturn NULL;\n");
|
||||||
fprintf(output, "\tvoid* tmp;\n");
|
fprintf(output, "\tvoid* tmp;\n");
|
||||||
|
fprintf(output, "\tjsonValue_t* tmpValue;\n");
|
||||||
|
|
||||||
for (size_t i = 0; i < info->memberno; i++) {
|
for (size_t i = 0; i < info->memberno; i++) {
|
||||||
struct memberinfo* member = info->members[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) {
|
if (strcmp(member->type->type, "string") == 0) {
|
||||||
fprintf(output, "\td->%s = (char*) tmp;\n", member->name);
|
fprintf(output, "\td->%s = (char*) tmp;\n", member->name);
|
||||||
} else if (member->type->isPointer) {
|
} else if (member->type->isPointer) {
|
||||||
|
|
Loading…
Reference in a new issue