d86ebd4
From 9aca3b6a087a396a81d7e26f4557eb97fecc1386 Mon Sep 17 00:00:00 2001
9c657ad
From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= <besser82@fedoraproject.org>
9c657ad
Date: Wed, 13 Dec 2017 19:22:52 +0100
d86ebd4
Subject: [PATCH] json_object: Avoid invalid free (and thus a segfault) when
9c657ad
 ref_count gets < 0
9c657ad
9c657ad
---
d86ebd4
 json_object.c | 5 +++++
d86ebd4
 1 file changed, 5 insertions(+)
9c657ad
9c657ad
diff --git a/json_object.c b/json_object.c
d86ebd4
index 042477a71b..7c7438d8ea 100644
9c657ad
--- a/json_object.c
9c657ad
+++ b/json_object.c
d86ebd4
@@ -182,6 +182,11 @@ int json_object_put(struct json_object *jso)
d86ebd4
 {
d86ebd4
 	if(!jso) return 0;
9c657ad
 
d86ebd4
+	/* Avoid invalid free and crash explicitly instead of (silently)
d86ebd4
+	 * segfaulting.
d86ebd4
+	 */
d86ebd4
+	assert(jso->_ref_count > 0);
d86ebd4
+
d86ebd4
 #if defined(HAVE_ATOMIC_BUILTINS) && defined(ENABLE_THREADING)
d86ebd4
 	/* Note: this only allow the refcount to remain correct
d86ebd4
 	 * when multiple threads are adjusting it.  It is still an error