aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-11 17:53:43 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-11 17:53:43 +0000
commit9200111bff45a2a8bea8c290ef16fe2859aecfea (patch)
tree8ba5a56a663f82059a5581fd50128b9b407caf48 /src/libstat
parentec52f9b4a1d093e23076d4fd8499b9ca7fe0a52c (diff)
downloadrspamd-9200111bff45a2a8bea8c290ef16fe2859aecfea.tar.gz
rspamd-9200111bff45a2a8bea8c290ef16fe2859aecfea.zip
[Fix] Plug memory leak introduced by #3153
Diffstat (limited to 'src/libstat')
-rw-r--r--src/libstat/backends/redis_backend.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index 84bc0ba77..107af3490 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -866,6 +866,13 @@ rspamd_redis_stat_keys (redisAsyncContext *c, gpointer r, gpointer priv)
more = true;
}
+ /* Clear the existing stuff */
+ PTR_ARRAY_FOREACH (cbdata->cur_keys, i, k) {
+ if (k) {
+ g_free (k);
+ }
+ }
+
g_ptr_array_set_size (cbdata->cur_keys, elts->elements);
for (i = 0; i < elts->elements; i ++) {
@@ -877,12 +884,14 @@ rspamd_redis_stat_keys (redisAsyncContext *c, gpointer r, gpointer priv)
rspamd_strlcpy (*pk, elt->str, elt->len + 1);
processed ++;
}
+ else {
+ pk = (gchar **)&g_ptr_array_index (cbdata->cur_keys, i);
+ *pk = NULL;
+ }
}
if (processed) {
- for (i = 0; i < cbdata->cur_keys->len; i ++) {
- k = (gchar *)g_ptr_array_index (cbdata->cur_keys, i);
-
+ PTR_ARRAY_FOREACH (cbdata->cur_keys, i, k) {
if (k) {
const gchar *learned_key = "learns";
@@ -1038,7 +1047,7 @@ rspamd_redis_async_stat_cb (struct rspamd_stat_async_elt *elt, gpointer d)
cbdata->inflight = 1;
cbdata->cur = ucl_object_typed_new (UCL_OBJECT);
cbdata->elt = redis_elt;
- cbdata->cur_keys = g_ptr_array_new ();
+ cbdata->cur_keys = g_ptr_array_sized_new (1000);
redis_elt->cbdata = cbdata;
/* XXX: deal with timeouts maybe */