From 90a11f3681016294de05bcd3aebc8c72d68bb42b Mon Sep 17 00:00:00 2001 From: kanoi Date: Wed, 4 May 2016 23:39:59 +1000 Subject: [PATCH] ckdb - fix some memory leaks --- src/ckdb.c | 4 +++- src/ckdb.h | 3 ++- src/ckdb_data.c | 9 +++++++++ src/ckdb_dbio.c | 14 +++++++++++--- src/klist.c | 2 +- src/ktree.c | 4 +++- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index 2019dfbd..12d57b79 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -1882,7 +1882,9 @@ static void dealloc_storage() FREE_TREE(events_hash); FREE_LISTS(events); FREE_ALL(ovents); - FREE_ALL(ips); + FREE_TREE(ips); + FREE_STORE_DATA(ips); + FREE_LIST(ips); FREE_ALL(auths); FREE_TREE(payouts_wid); diff --git a/src/ckdb.h b/src/ckdb.h index bf639915..6702e33e 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -52,7 +52,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.5" -#define CKDB_VERSION DB_VERSION"-2.104" +#define CKDB_VERSION DB_VERSION"-2.105" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -2803,6 +2803,7 @@ extern void free_users_data(K_ITEM *item); extern void free_workinfo_data(K_ITEM *item); extern void free_sharesummary_data(K_ITEM *item); extern void free_payouts_data(K_ITEM *item); +extern void free_ips_data(K_ITEM *item); extern void free_optioncontrol_data(K_ITEM *item); extern void free_markersummary_data(K_ITEM *item); extern void free_workmarkers_data(K_ITEM *item); diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 2604e5cc..3636031f 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -73,6 +73,15 @@ void free_payouts_data(K_ITEM *item) FREENULL(payouts->stats); } +void free_ips_data(K_ITEM *item) +{ + IPS *ips; + + DATA_IPS(ips, item); + LIST_MEM_SUB(ips_free, ips->description); + FREENULL(ips->description); +} + void free_sharesummary_data(K_ITEM *item) { SHARESUMMARY *sharesummary; diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index e42252de..42de12ea 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -2981,6 +2981,8 @@ bool optioncontrol_fill(PGconn *conn) K_WUNLOCK(optioncontrol_free); PQclear(res); + for (n = 0; n < par; n++) + free(params[n]); if (ok) { LOGDEBUG("%s(): built", __func__); @@ -3384,7 +3386,9 @@ bool workinfo_fill(PGconn *conn) flail: res = PQexec(conn, "Commit", CKPQ_READ); PQclear(res); - + for (n = 0; n < par; n++) + free(params[n]); + free(sel); if (ok) { LOGDEBUG("%s(): built", __func__); @@ -7053,7 +7057,9 @@ void ips_add(char *group, char *ip, char *eventname, bool is_event, char *des, STRNCPY(ips->ip, ip); STRNCPY(ips->eventname, eventname); ips->is_event = is_event; - if (des) { + if (!des) + ips->description = NULL; + else { ips->description = strdup(des); if (!ips->description) quithere(1, "strdup OOM"); @@ -7081,7 +7087,9 @@ void ips_add(char *group, char *ip, char *eventname, bool is_event, char *des, } } if (ok) { - if (des) { + if (!des) + ips2->description = NULL; + else { ips2->description = strdup(des); LIST_MEM_ADD(ips_free, ips2->description); } diff --git a/src/klist.c b/src/klist.c index 66298ea1..0b88a8d8 100644 --- a/src/klist.c +++ b/src/klist.c @@ -1,6 +1,6 @@ /* * Copyright 2013-2014 Andrew Smith - BlackArrow Ltd - * Copyright 2015 Andrew Smith + * Copyright 2015-2016 Andrew Smith * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free diff --git a/src/ktree.c b/src/ktree.c index b13c5585..e97161ff 100644 --- a/src/ktree.c +++ b/src/ktree.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2015 Andrew Smith + * Copyright 1995-2016 Andrew Smith * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -1097,4 +1097,6 @@ void _free_ktree(K_TREE *tree, void (*free_funct)(void *), KTREE_FFL_ARGS) tree->node_store = k_free_store(tree->node_store); tree->node_free = k_free_list(tree->node_free); + + free(tree); }