From e53c2cc67e7ba389db2ceb81eb7cdb657a03548e Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Wed, 14 Sep 2022 19:15:01 +0200 Subject: fix refcounting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bjørn Mork --- Makefile | 2 +- obinsectd.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b7cf63c..9c3f705 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := 0.07 +VERSION := 0.08 LDFLAGS=$(shell pkg-config --libs json-c) $(shell pkg-config --libs libmosquitto) CFLAGS=-Wall $(shell pkg-config --cflags json-c) $(shell pkg-config --cflags libmosquitto) -DVERSION='"$(VERSION)"' -DWITH_TLS diff --git a/obinsectd.c b/obinsectd.c index 81430fe..f57aec8 100644 --- a/obinsectd.c +++ b/obinsectd.c @@ -1141,6 +1141,7 @@ static void add_keyval(json_object *pubcfg, json_object *pub, const char *key, j if (!json_object_object_get_ex(pubcfg, key, &tmp)) return; + /* take an extra refcount on val so we can use it in the loop below too */ json_object_object_add(pub, key, json_object_get(val)); for (i = 0; i < json_object_array_length(tmp); i++) { arrayname = json_object_get_string(json_object_array_get_idx(tmp, i)); @@ -1160,6 +1161,8 @@ static void add_keyval(json_object *pubcfg, json_object *pub, const char *key, j json_object_object_add(obj, key, json_object_get(val)); } + /* drop extra recount again */ + json_object_put(val); } static void set_current_list(const char *listname) -- cgit v1.2.3