diff options
author | ulfvonbelow <striness@tilde.club> | 2024-05-02 19:31:25 -0500 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2024-05-06 09:24:12 +0200 |
commit | 0f1aa84f60d360a3e3aac17eb8fdb269bd80e866 (patch) | |
tree | 45228705a33f79a672f65a259bf7e63d6999ec24 | |
parent | 092ed05ece2bfd8c0393a8a44134b3d0e0e9f375 (diff) | |
download | gnunet-0f1aa84f60d360a3e3aac17eb8fdb269bd80e866.tar.gz gnunet-0f1aa84f60d360a3e3aac17eb8fdb269bd80e866.zip |
peerstore: fix memory leaks in peerstore_api.c.
Signed-off-by: Martin Schanzenbach <schanzen@gnunet.org>
-rw-r--r-- | src/service/peerstore/peerstore_api.c | 34 |
1 files 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) | |||
446 | { | 446 | { |
447 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnect initiated from client.\n"); | 447 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnect initiated from client.\n"); |
448 | disconnect (h); | 448 | disconnect (h); |
449 | GNUNET_free (h); | ||
449 | } | 450 | } |
450 | 451 | ||
451 | 452 | ||
@@ -453,6 +454,15 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
453 | /******************* STORE FUNCTIONS *********************/ | 454 | /******************* STORE FUNCTIONS *********************/ |
454 | /******************************************************************************/ | 455 | /******************************************************************************/ |
455 | 456 | ||
457 | static void | ||
458 | destroy_storecontext(struct GNUNET_PEERSTORE_StoreContext *sc) | ||
459 | { | ||
460 | GNUNET_CONTAINER_DLL_remove (sc->h->store_head, sc->h->store_tail, sc); | ||
461 | GNUNET_free (sc->sub_system); | ||
462 | GNUNET_free (sc->value); | ||
463 | GNUNET_free (sc->key); | ||
464 | GNUNET_free (sc); | ||
465 | } | ||
456 | 466 | ||
457 | /** | 467 | /** |
458 | * Cancel a store request | 468 | * Cancel a store request |
@@ -465,11 +475,7 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | |||
465 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 475 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
466 | "store cancel with sc %p \n", | 476 | "store cancel with sc %p \n", |
467 | sc); | 477 | sc); |
468 | GNUNET_CONTAINER_DLL_remove (sc->h->store_head, sc->h->store_tail, sc); | 478 | destroy_storecontext(sc); |
469 | GNUNET_free (sc->sub_system); | ||
470 | GNUNET_free (sc->value); | ||
471 | GNUNET_free (sc->key); | ||
472 | GNUNET_free (sc); | ||
473 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 479 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
474 | "store cancel with sc %p is null\n", | 480 | "store cancel with sc %p is null\n", |
475 | sc); | 481 | sc); |
@@ -576,7 +582,7 @@ handle_store_result (void *cls, const struct PeerstoreResultMessage *msg) | |||
576 | } | 582 | } |
577 | if (NULL != sc->cont) | 583 | if (NULL != sc->cont) |
578 | sc->cont (sc->cont_cls, ntohl (msg->result)); | 584 | sc->cont (sc->cont_cls, ntohl (msg->result)); |
579 | GNUNET_CONTAINER_DLL_remove (h->store_head, h->store_tail, sc); | 585 | destroy_storecontext (sc); |
580 | } | 586 | } |
581 | 587 | ||
582 | 588 | ||
@@ -584,6 +590,15 @@ handle_store_result (void *cls, const struct PeerstoreResultMessage *msg) | |||
584 | /******************* ITERATE FUNCTIONS *********************/ | 590 | /******************* ITERATE FUNCTIONS *********************/ |
585 | /******************************************************************************/ | 591 | /******************************************************************************/ |
586 | 592 | ||
593 | static void | ||
594 | destroy_iteratecontext(struct GNUNET_PEERSTORE_IterateContext *ic) | ||
595 | { | ||
596 | GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic); | ||
597 | GNUNET_free (ic->sub_system); | ||
598 | GNUNET_free (ic->key); | ||
599 | GNUNET_free (ic); | ||
600 | } | ||
601 | |||
587 | 602 | ||
588 | /** | 603 | /** |
589 | * When a response for iterate request is received | 604 | * When a response for iterate request is received |
@@ -609,7 +624,7 @@ handle_iterate_end (void *cls, const struct PeerstoreResultMessage *msg) | |||
609 | if (NULL != ic->callback) | 624 | if (NULL != ic->callback) |
610 | ic->callback (ic->callback_cls, NULL, NULL); | 625 | ic->callback (ic->callback_cls, NULL, NULL); |
611 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up iteration with rid %u\n", ic->rid); | 626 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up iteration with rid %u\n", ic->rid); |
612 | GNUNET_CONTAINER_DLL_remove (h->iterate_head, h->iterate_tail, ic); | 627 | destroy_iteratecontext (ic); |
613 | } | 628 | } |
614 | 629 | ||
615 | 630 | ||
@@ -719,10 +734,7 @@ GNUNET_PEERSTORE_iteration_stop (struct GNUNET_PEERSTORE_IterateContext *ic) | |||
719 | if (NULL != ic->h->mq) | 734 | if (NULL != ic->h->mq) |
720 | GNUNET_MQ_send (ic->h->mq, ev); | 735 | GNUNET_MQ_send (ic->h->mq, ev); |
721 | } | 736 | } |
722 | GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic); | 737 | destroy_iteratecontext (ic); |
723 | GNUNET_free (ic->sub_system); | ||
724 | GNUNET_free (ic->key); | ||
725 | GNUNET_free (ic); | ||
726 | } | 738 | } |
727 | 739 | ||
728 | 740 | ||