From e1f7a1367dd7ea9244649dbf065e46a2059904cb Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Wed, 16 Aug 2017 13:49:51 +0200 Subject: [PATCH] consistently use json_delete --- gcache.c | 2 +- hooks.c | 2 +- recorder.c | 6 +----- storage.c | 5 ++--- util.c | 1 - 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/gcache.c b/gcache.c index 0cc3397..6aec098 100644 --- a/gcache.c +++ b/gcache.c @@ -424,7 +424,7 @@ bool gcache_enum(char *user, char *device, struct gcache *gc, char *key_part, in wp.json = jsonpayload; if (func && func(UB(ks), &wp, lat, lon) == true) { - json_remove_from_parent(jio); + json_delete(jio); json_append_member(json, "io", json_mkbool(wp.io)); if (gcache_json_put(gc, UB(ks), json) != 0) { olog(LOG_ERR, "gcache_enum: cannot rewrite key %s", UB(ks)); diff --git a/hooks.c b/hooks.c index 3f67ad8..46faf80 100644 --- a/hooks.c +++ b/hooks.c @@ -390,7 +390,7 @@ void hooks_transition(struct udata *ud, char *user, char *device, int event, cha JsonNode *j; if ((j = json_find_member(json, "_type")) != NULL) { - json_remove_from_parent(j); + json_delete(j); } json_append_member(json, "_type", json_mkstring("transition")); json_append_member(json, "event", diff --git a/recorder.c b/recorder.c index c68530e..69569fd 100644 --- a/recorder.c +++ b/recorder.c @@ -362,7 +362,6 @@ void waypoints_dump(struct udata *ud, UT_string *username, UT_string *device, ch return; if ((j = json_find_member(json, "r")) != NULL) { - json_remove_from_parent(j); json_delete(j); js = json_stringify(json, NULL); json_delete(json); @@ -780,7 +779,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle if ((j = json_find_member(json, "tst")) != NULL) { if (j->tag == JSON_STRING) { tst = strtoul(j->string_, NULL, 10); - json_remove_from_parent(j); json_delete(j); json_append_member(json, "tst", json_mknumber(tst)); } else { @@ -804,7 +802,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle if ((j = json_find_member(json, "acc")) != NULL) { if (j->tag == JSON_STRING) { acc = atof(j->string_); - json_remove_from_parent(j); json_delete(j); json_append_member(json, "acc", json_mknumber(acc)); } @@ -842,7 +839,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle if ((blen = gcache_get(ud->t2t, topic, newtid, sizeof(newtid))) > 0) { if ((j = json_find_member(json, "tid")) != NULL) { - json_remove_from_parent(j); json_delete(j); } json_append_member(json, "tid", json_mkstring(newtid)); @@ -877,7 +873,7 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle if ((geo = hook_revgeo(ud, lua_func, topic, UB(username), UB(device), lat, lon)) != NULL) { if ((j = json_find_member(geo, "_rec")) != NULL) { if (j->bool_ == true) { - json_remove_from_parent(j); + json_delete(j); json_copy_to_object(json, geo, false); geo = NULL; /* Reset so it's not copied again later */ } diff --git a/storage.c b/storage.c index 9395c28..c07dae1 100644 --- a/storage.c +++ b/storage.c @@ -513,7 +513,6 @@ static void lsscan(char *pathpat, time_t s_lo, time_t s_hi, JsonNode *obj, int r if ((jarr = json_find_member(obj, "results")) == NULL) { jarr = json_mkarray(); } else { - json_remove_from_parent(jarr); json_delete(jarr); } @@ -1538,7 +1537,7 @@ static bool load_otrw_waypoints(struct udata *ud, JsonNode *wplist, char *user, if (strcmp(type->string_, "waypoint") != 0) return (false); - json_remove_from_parent(type); + json_delete(type); if ((rad = json_find_member(n, "rad")) == NULL) continue; @@ -1553,7 +1552,7 @@ static bool load_otrw_waypoints(struct udata *ud, JsonNode *wplist, char *user, /* It turns out tst was a key, but it breaks on iOS when dumped * waypoints are re-imported. we'll use the geohash of lat/lon here */ - json_remove_from_parent(tst); + json_delete(tst); utstring_renew(key); utstring_printf(key, "%s-%s-%s", user, device, diff --git a/util.c b/util.c index 2eff7c2..fdce2b4 100644 --- a/util.c +++ b/util.c @@ -617,7 +617,6 @@ double number(JsonNode *j, char *element) } else if (m->tag == JSON_STRING) { d = atof(m->string_); /* Normalize to number */ - json_remove_from_parent(m); json_delete(m); json_append_member(j, element, json_mknumber(d)); return (d);