aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2022-09-14 20:44:22 +0200
committerBjørn Mork <bjorn@mork.no>2022-09-14 20:44:22 +0200
commit26be6715d14c0107b4d2c16b3e9076da4091af4f (patch)
tree178d9edce49485ab15e71c2f3cebdeb7435c1e92
parentf7c340d71c385a8256502cf63f57b62d9844e631 (diff)
more memleak fixingv0.10
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r--Makefile2
-rw-r--r--obinsectd.c10
2 files changed, 8 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 27dcdc7..d91476e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION := 0.09
+VERSION := 0.10
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 29de55b..7829592 100644
--- a/obinsectd.c
+++ b/obinsectd.c
@@ -1252,6 +1252,10 @@ static json_object *format_value(const char *key, json_object *val)
}
ival = json_object_get_int(val);
+
+ /* we can drop val now */
+ json_object_put(val);
+
if (ifactor) {
if (!unit)
return json_object_new_int(ival * ifactor);
@@ -1269,16 +1273,16 @@ static void add_obis(json_object *pubcfg, json_object *pub, const char *key, jso
const char *alias = get_alias(key);
json_object *tmp, *newval = val;
+ /* we take an extra ref every time newval is used, and then drop one of them in the end */
newval = format_value(key, val);
if (json_object_object_get_ex(pub, "normal", &tmp))
- json_object_object_add(tmp, key, newval);
+ json_object_object_add(tmp, key, json_object_get(newval));
- /* 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, json_object_get(newval));
- add_keyval(pubcfg, pub, alias, newval, true);
+ add_keyval(pubcfg, pub, alias, json_object_get(newval), true);
}
/* drop the extra ref */