diff options
author | Bjørn Mork <bjorn@mork.no> | 2022-09-14 20:29:09 +0200 |
---|---|---|
committer | Bjørn Mork <bjorn@mork.no> | 2022-09-14 20:29:09 +0200 |
commit | f7c340d71c385a8256502cf63f57b62d9844e631 (patch) | |
tree | 3ba8eb0b34dcf9ca92cc782f1fbe6769ad37c1a5 | |
parent | e53c2cc67e7ba389db2ceb81eb7cdb657a03548e (diff) |
take extra ref for repeated add_keyval()v0.09
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | obinsectd.c | 9 |
2 files changed, 8 insertions, 3 deletions
@@ -1,4 +1,4 @@ -VERSION := 0.08 +VERSION := 0.09 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 f57aec8..29de55b 100644 --- a/obinsectd.c +++ b/obinsectd.c @@ -1272,12 +1272,17 @@ static void add_obis(json_object *pubcfg, json_object *pub, const char *key, jso newval = format_value(key, val); if (json_object_object_get_ex(pub, "normal", &tmp)) json_object_object_add(tmp, key, newval); - add_keyval(pubcfg, pub, key, newval, true); + + /* taking extra ref in case we need to use newval below */ + add_keyval(pubcfg, pub, key, json_object_get(newval), true); if (alias) { if (json_object_object_get_ex(pub, "alias", &tmp)) - json_object_object_add(tmp, alias, newval); + json_object_object_add(tmp, alias, json_object_get(newval)); add_keyval(pubcfg, pub, alias, newval, true); } + + /* drop the extra ref */ + json_object_put(newval); } /* |