]> granicus.if.org Git - json-c/commitdiff
json_object: Avoid invalid free (and thus a segfault) when ref_count gets < 0
authorBjörn Esser <besser82@fedoraproject.org>
Wed, 13 Dec 2017 18:22:52 +0000 (19:22 +0100)
committerBjörn Esser <besser82@fedoraproject.org>
Thu, 14 Dec 2017 13:36:07 +0000 (14:36 +0100)
json_object.c

index 042477a71b8cc3963eb792a6c5c74f953532d5ff..7c7438d8ea21b5e823d59bd8e6221d3f04246d0c 100644 (file)
@@ -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