From 86ff2216634d49d22c8fdd3b14b87b54e29a4c54 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 1 Sep 2017 17:12:16 -0700 Subject: [PATCH] I think this should fix the access to already-freed memory Also drop the reference to the JSON parser when disconnecting a JSON object from the parse tree. --- jsonpull/jsonpull.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jsonpull/jsonpull.c b/jsonpull/jsonpull.c index 3067f4fe..78e6472a 100644 --- a/jsonpull/jsonpull.c +++ b/jsonpull/jsonpull.c @@ -708,6 +708,21 @@ void json_free(json_object *o) { free(o); } +static void json_disconnect_parser(json_object *o) { + if (o->type == JSON_HASH) { + for (size_t i = 0; i < o->length; i++) { + json_disconnect_parser(o->keys[i]); + json_disconnect_parser(o->values[i]); + } + } else if (o->type == JSON_ARRAY) { + for (size_t i = 0; i < o->length; i++) { + json_disconnect_parser(o->array[i]); + } + } + + o->parser = NULL; +} + void json_disconnect(json_object *o) { // Expunge references to this as an array element // or a hash key or value. @@ -761,6 +776,7 @@ void json_disconnect(json_object *o) { o->parser->root = NULL; } + json_disconnect_parser(o); o->parent = NULL; }