forked from Telodendria/Telodendria
Fix more memory leaks in json.
By doing a little reference tracking, we can make sure we don't miss any JsonValues that may be floating around by the time we're done.
This commit is contained in:
parent
efb27c9db8
commit
d81600d944
2 changed files with 14 additions and 2 deletions
3
TODO.txt
3
TODO.txt
|
@ -11,7 +11,8 @@ Key:
|
|||
Milestone: v0.3.0
|
||||
-----------------
|
||||
|
||||
[ ] Fix leaks in json
|
||||
[x] Fix leaks in json
|
||||
[ ] Debug ARM64 Debian
|
||||
|
||||
[ ] Cytoplasm
|
||||
[ ] Debug OpenSSL
|
||||
|
|
|
@ -47,6 +47,10 @@ query(char *select, HashMap * json)
|
|||
char *key;
|
||||
JsonValue *rootVal = JsonValueObject(json);
|
||||
JsonValue *val = rootVal;
|
||||
Array *cleanUp = ArrayCreate();
|
||||
size_t i;
|
||||
|
||||
ArrayAdd(cleanUp, rootVal);
|
||||
|
||||
key = strtok(select, "->");
|
||||
|
||||
|
@ -67,9 +71,11 @@ query(char *select, HashMap * json)
|
|||
{
|
||||
case JSON_ARRAY:
|
||||
val = JsonValueInteger(ArraySize(JsonValueAsArray(val)));
|
||||
ArrayAdd(cleanUp, val);
|
||||
break;
|
||||
case JSON_STRING:
|
||||
val = JsonValueInteger(strlen(JsonValueAsString(val)));
|
||||
ArrayAdd(cleanUp, val);
|
||||
break;
|
||||
default:
|
||||
val = NULL;
|
||||
|
@ -89,6 +95,7 @@ query(char *select, HashMap * json)
|
|||
}
|
||||
|
||||
val = JsonValueArray(arr);
|
||||
ArrayAdd(cleanUp, val);
|
||||
}
|
||||
else if (JsonValueType(val) == JSON_STRING && StrEquals(keyName + 1, "decode"))
|
||||
{
|
||||
|
@ -167,7 +174,11 @@ query(char *select, HashMap * json)
|
|||
StreamPutc(StreamStdout(), '\n');
|
||||
}
|
||||
|
||||
JsonValueFree(rootVal);
|
||||
for (i = 0; i < ArraySize(cleanUp); i++)
|
||||
{
|
||||
JsonValueFree(ArrayGet(cleanUp, i));
|
||||
}
|
||||
ArrayFree(cleanUp);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue