From b41d152cd1a98b23c1ea0468ed190e2876eebfde Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 23 Feb 2016 17:31:00 +0100 Subject: [PATCH] valgrind is happier --- recorder.c | 17 +++++++++++------ storage.c | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/recorder.c b/recorder.c index a25b323..bbb9a3c 100644 --- a/recorder.c +++ b/recorder.c @@ -599,7 +599,7 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle char *topics[42]; int count = 0, cached; static UT_string *basetopic = NULL, *username = NULL, *device = NULL, *addr = NULL, *cc = NULL, *ghash = NULL, *ts = NULL; - static UT_string *reltopic = NULL; + static UT_string *reltopic = NULL, *filename = NULL; char *jsonstring, *_typestr = NULL; time_t now; int pingping = FALSE, skipslash = 0; @@ -1027,7 +1027,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle json_append_member(json, "ghash", json_mkstring(UB(ghash))); if (_type == T_LOCATION || _type == T_WAYPOINT) { - UT_string *filename = NULL; char *component; utstring_renew(filename); @@ -1165,10 +1164,10 @@ static char *mosquitto_reason(int rc) void on_disconnect(struct mosquitto *mosq, void *userdata, int reason) { - struct udata *ud = (struct udata *)userdata; + // struct udata *ud = (struct udata *)userdata; if (reason == 0) { // client wish - gcache_close(ud->gc); + ; } else { olog(LOG_INFO, "Disconnected. Reason: 0x%X [%s]", reason, mosquitto_reason(reason)); } @@ -1704,12 +1703,16 @@ int main(int argc, char **argv) json_delete(ud->topics); - if (ud->t2t) - gcache_close(ud->t2t); + gcache_close(ud->gc); + gcache_close(ud->t2t); + gcache_close(ud->httpfriends); #ifdef WITH_LUA if (ud->luadb) gcache_close(ud->luadb); #endif +# ifdef WITH_ENCRYPT + gcache_close(ud->keydb); +# endif free(ud->label); @@ -1721,6 +1724,8 @@ int main(int argc, char **argv) hooks_exit(ud->luadata, "recorder stops"); #endif + revgeo_free(); + #ifdef WITH_MQTT mosquitto_disconnect(mosq); diff --git a/storage.c b/storage.c index 4a264e9..bf923d3 100644 --- a/storage.c +++ b/storage.c @@ -472,20 +472,12 @@ static void lsscan(char *pathpat, time_t s_lo, time_t s_hi, JsonNode *obj, int r { struct dirent **namelist; int i, n; - JsonNode *jarr; + JsonNode *jarr = NULL; static UT_string *path = NULL; if (obj == NULL || obj->tag != JSON_OBJECT) return; - /* If our obj contains the "results" array, use that - * and remove from obj; we'll add it back later. - */ - if ((jarr = json_find_member(obj, "results")) == NULL) { - jarr = json_mkarray(); - } else { - json_remove_from_parent(jarr); - } utstring_renew(path); @@ -498,6 +490,15 @@ static void lsscan(char *pathpat, time_t s_lo, time_t s_hi, JsonNode *obj, int r return; } + /* If our obj contains the "results" array, use that + * and remove from obj; we'll add it back later. + */ + if ((jarr = json_find_member(obj, "results")) == NULL) { + jarr = json_mkarray(); + } else { + json_remove_from_parent(jarr); + } + if (reverse) { for (i = n - 1; i >= 0; i--) { utstring_clear(path); @@ -529,7 +530,7 @@ static void lsscan(char *pathpat, time_t s_lo, time_t s_hi, JsonNode *obj, int r JsonNode *lister(char *user, char *device, time_t s_lo, time_t s_hi, int reverse) { JsonNode *json = json_mkobject(); - UT_string *path = NULL; + static UT_string *path = NULL; char *bp; utstring_renew(path); @@ -567,7 +568,7 @@ JsonNode *lister(char *user, char *device, time_t s_lo, time_t s_hi, int reverse JsonNode *multilister(JsonNode *udpairs, time_t s_lo, time_t s_hi, int reverse) { JsonNode *json = json_mkobject(), *ud; - UT_string *path = NULL; + static UT_string *path = NULL; char *pairs[3]; int np;