From: Christian Grothoff Date: Mon, 18 Jun 2012 09:46:40 +0000 (+0000) Subject: -implementing freeing of state on exit X-Git-Tag: initial-import-from-subversion-38251~13002 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=cdef950ccd51ceecce302991aa6d673f23fdea34;p=oweals%2Fgnunet.git -implementing freeing of state on exit --- diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index db5b4537b..c3b0411d0 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c @@ -46,7 +46,7 @@ struct WorkItem /** * Filename of the work item. */ - const char *filename; + char *filename; /** * Unique identity for this work item (used to detect @@ -515,6 +515,26 @@ run (void *cls, char *const *args, const char *cfgfile, } +/** + * Free memory associated with the work item from the work_finished map. + * + * @param cls NULL (unused) + * @param key key of the item in the map (unused) + * @param value the 'struct WorkItem' to free + * @return GNUNET_OK to continue to iterate + */ +static int +free_item (void *cls, + const struct GNUNET_HashCode *key, + void *value) +{ + struct WorkItem *wi = value; + + GNUNET_free (wi->filename); + GNUNET_free (wi); + return GNUNET_OK; +} + /** * The main function to automatically publish content to GNUnet. * @@ -547,6 +567,7 @@ main (int argc, char *const *argv) 0, &GNUNET_GETOPT_set_one, &verbose}, GNUNET_GETOPT_OPTION_END }; + struct WorkItem *wi; int ok; if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) @@ -556,7 +577,16 @@ main (int argc, char *const *argv) gettext_noop ("Automatically publish files from a directory on GNUnet"), options, &run, NULL)) ? ret : 1; - // FIXME: free memory in work lists and hash map... + (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, + &free_item, + NULL); + GNUNET_CONTAINER_multihashmap_destroy (work_finished); + while (NULL != (wi = work_head)) + { + GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi); + GNUNET_free (wi->filename); + GNUNET_free (wi); + } return ok; }