From e22cf38eacd2700ee42afc4d65f4d1561d3fcc5a Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Tue, 23 May 2023 20:34:27 +0000 Subject: [PATCH] Fix leaks in json. --- TODO.txt | 2 +- tools/src/json.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/TODO.txt b/TODO.txt index 1a55b63..b5cec39 100644 --- a/TODO.txt +++ b/TODO.txt @@ -19,7 +19,7 @@ Milestone: v0.3.0 [x] Profiles [ ] Directory -[ ] Fix leaks in http, json +[x] Fix leaks in http, json [x] Remove TelodendriaGenerateMemReport() [ ] Cytoplasm diff --git a/tools/src/json.c b/tools/src/json.c index 80e3ecd..ee2f2c2 100644 --- a/tools/src/json.c +++ b/tools/src/json.c @@ -45,7 +45,8 @@ static void query(char *select, HashMap * json) { char *key; - JsonValue *val = JsonValueObject(json); + JsonValue *rootVal = JsonValueObject(json); + JsonValue *val = rootVal; key = strtok(select, "->"); @@ -165,6 +166,8 @@ query(char *select, HashMap * json) JsonEncodeValue(val, StreamStdout(), JSON_PRETTY); StreamPutc(StreamStdout(), '\n'); } + + JsonValueFree(rootVal); } static void @@ -175,6 +178,7 @@ encode(char *str) JsonEncodeValue(val, StreamStdout(), JSON_DEFAULT); JsonValueFree(val); StreamPutc(StreamStdout(), '\n'); + JsonValueFree(val); } int @@ -230,6 +234,5 @@ Main(Array * args) break; } - JsonFree(json); return 0; }