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.
This commit is contained in:
Eric Fischer 2017-09-01 17:12:16 -07:00
parent 681907e88d
commit 86ff221663

View File

@ -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;
}