From: Björn Esser Date: Wed, 13 Dec 2017 18:22:52 +0000 (+0100) Subject: json_object: Avoid invalid free (and thus a segfault) when ref_count gets < 0 X-Git-Tag: json-c-0.14-20200419~139^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F389%2Fhead;p=thirdparty%2Fjson-c.git json_object: Avoid invalid free (and thus a segfault) when ref_count gets < 0 --- diff --git a/json_object.c b/json_object.c index 042477a7..7c7438d8 100644 --- a/json_object.c +++ b/json_object.c @@ -182,6 +182,11 @@ int json_object_put(struct json_object *jso) { if(!jso) return 0; + /* Avoid invalid free and crash explicitly instead of (silently) + * segfaulting. + */ + assert(jso->_ref_count > 0); + #if defined(HAVE_ATOMIC_BUILTINS) && defined(ENABLE_THREADING) /* Note: this only allow the refcount to remain correct * when multiple threads are adjusting it. It is still an error