View Issue Details

IDProjectCategoryView StatusLast Update
0008793GNUnetpeerstorepublic2024-06-08 12:03
Reporterulfvonbelow Assigned Toschanzen  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86-64OSGuix SystemOS Versiona1d711c92e
Product Version0.21.1 
Fixed in Version0.21.2 
Summary0008793: memory leaks in peerstore api
Descriptioniterate and store contexts are only freed when they are canceled, not when they complete normally. Additionally, disconnecting from the peerstore service doesn't free the peerstore handle.
Steps To Reproduce1. ./configure --enable-sanitizer ; make ; make check
2. Observe memory leaks in anything that uses peerstore api
Additional InformationPatch attached.
TagsNo tags attached.

Activities

schanzen

2024-05-05 14:15

administrator   ~0022348

Hello. I think you forgot to attach the patch. If you still have it it would be great if you can provide it, otherwise I will investigate myself based on the description.

ulfvonbelow

2024-05-06 07:43

reporter   ~0022354

Oops
0001-peerstore-fix-memory-leaks-in-peerstore_api.c.patch (3,384 bytes)   
From 2c83cbabc504d1082595ae1cf68786902ee06770 Mon Sep 17 00:00:00 2001
From: ulfvonbelow <striness@tilde.club>
Date: Thu, 2 May 2024 19:31:25 -0500
Subject: [PATCH] peerstore: fix memory leaks in peerstore_api.c.

---
 src/service/peerstore/peerstore_api.c | 34 ++++++++++++++++++---------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/service/peerstore/peerstore_api.c b/src/service/peerstore/peerstore_api.c
index 19cb1213e..898d58a2c 100644
--- a/src/service/peerstore/peerstore_api.c
+++ b/src/service/peerstore/peerstore_api.c
@@ -446,6 +446,7 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h)
 {
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnect initiated from client.\n");
   disconnect (h);
+  GNUNET_free (h);
 }
 
 
@@ -453,6 +454,15 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h)
 /*******************            STORE FUNCTIONS           *********************/
 /******************************************************************************/
 
+static void
+destroy_storecontext(struct GNUNET_PEERSTORE_StoreContext *sc)
+{
+  GNUNET_CONTAINER_DLL_remove (sc->h->store_head, sc->h->store_tail, sc);
+  GNUNET_free (sc->sub_system);
+  GNUNET_free (sc->value);
+  GNUNET_free (sc->key);
+  GNUNET_free (sc);
+}
 
 /**
  * Cancel a store request
@@ -465,11 +475,7 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc)
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "store cancel with sc %p \n",
        sc);
-  GNUNET_CONTAINER_DLL_remove (sc->h->store_head, sc->h->store_tail, sc);
-  GNUNET_free (sc->sub_system);
-  GNUNET_free (sc->value);
-  GNUNET_free (sc->key);
-  GNUNET_free (sc);
+  destroy_storecontext(sc);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "store cancel with sc %p is null\n",
        sc);
@@ -576,7 +582,7 @@ handle_store_result (void *cls, const struct PeerstoreResultMessage *msg)
   }
   if (NULL != sc->cont)
     sc->cont (sc->cont_cls, ntohl (msg->result));
-  GNUNET_CONTAINER_DLL_remove (h->store_head, h->store_tail, sc);
+  destroy_storecontext (sc);
 }
 
 
@@ -584,6 +590,15 @@ handle_store_result (void *cls, const struct PeerstoreResultMessage *msg)
 /*******************           ITERATE FUNCTIONS          *********************/
 /******************************************************************************/
 
+static void
+destroy_iteratecontext(struct GNUNET_PEERSTORE_IterateContext *ic)
+{
+  GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic);
+  GNUNET_free (ic->sub_system);
+  GNUNET_free (ic->key);
+  GNUNET_free (ic);
+}
+
 
 /**
  * When a response for iterate request is received
@@ -609,7 +624,7 @@ handle_iterate_end (void *cls, const struct PeerstoreResultMessage *msg)
   if (NULL != ic->callback)
     ic->callback (ic->callback_cls, NULL, NULL);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up iteration with rid %u\n", ic->rid);
-  GNUNET_CONTAINER_DLL_remove (h->iterate_head, h->iterate_tail, ic);
+  destroy_iteratecontext (ic);
 }
 
 
@@ -719,10 +734,7 @@ GNUNET_PEERSTORE_iteration_stop (struct GNUNET_PEERSTORE_IterateContext *ic)
     if (NULL != ic->h->mq)
       GNUNET_MQ_send (ic->h->mq, ev);
   }
-  GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic);
-  GNUNET_free (ic->sub_system);
-  GNUNET_free (ic->key);
-  GNUNET_free (ic);
+  destroy_iteratecontext (ic);
 }
 
 
-- 
2.41.0

schanzen

2024-05-06 09:24

administrator   ~0022355

applied

schanzen

2024-06-08 12:03

administrator   ~0022548

0.21.2 released

Issue History

Date Modified Username Field Change
2024-05-03 04:01 ulfvonbelow New Issue
2024-05-05 14:15 schanzen Note Added: 0022348
2024-05-06 07:43 ulfvonbelow Note Added: 0022354
2024-05-06 07:43 ulfvonbelow File Added: 0001-peerstore-fix-memory-leaks-in-peerstore_api.c.patch
2024-05-06 09:24 schanzen Assigned To => schanzen
2024-05-06 09:24 schanzen Status new => resolved
2024-05-06 09:24 schanzen Resolution open => fixed
2024-05-06 09:24 schanzen Fixed in Version => 0.21.2
2024-05-06 09:24 schanzen Note Added: 0022355
2024-06-08 12:03 schanzen Note Added: 0022548
2024-06-08 12:03 schanzen Status resolved => closed