summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Haszlakiewicz <erh+git@nimenees.com>2017-12-14 09:28:06 -0500
committerGitHub <noreply@github.com>2017-12-14 09:28:06 -0500
commit5ea6a05bfa43c9ba438fbc0eaea600edd6d72b88 (patch)
tree39398a481657691c40295aa1f9a6a18cd686a34a
parent8c214902d93dfcafea1c6025f985c199da5e061d (diff)
parent9aca3b6a087a396a81d7e26f4557eb97fecc1386 (diff)
downloadjson-c-5ea6a05bfa43c9ba438fbc0eaea600edd6d72b88.tar.gz
Merge pull request #389 from besser82/bugfix/invalid_free
json_object: Avoid double free (and thus a segfault) when ref_count gets < 0
-rw-r--r--json_object.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/json_object.c b/json_object.c
index 042477a..7c7438d 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