diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-18 09:46:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-18 09:46:40 +0000 |
commit | cdef950ccd51ceecce302991aa6d673f23fdea34 (patch) | |
tree | fc09258a9ac4fc2524c0b0554629b59990e1df9c /src/fs/gnunet-auto-share.c | |
parent | 64e58c7fc37d49c076b1da06fc74e05c3d9a49ca (diff) | |
download | gnunet-cdef950ccd51ceecce302991aa6d673f23fdea34.tar.gz gnunet-cdef950ccd51ceecce302991aa6d673f23fdea34.zip |
-implementing freeing of state on exit
Diffstat (limited to 'src/fs/gnunet-auto-share.c')
-rw-r--r-- | src/fs/gnunet-auto-share.c | 34 |
1 files changed, 32 insertions, 2 deletions
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 | |||
46 | /** | 46 | /** |
47 | * Filename of the work item. | 47 | * Filename of the work item. |
48 | */ | 48 | */ |
49 | const char *filename; | 49 | char *filename; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Unique identity for this work item (used to detect | 52 | * Unique identity for this work item (used to detect |
@@ -516,6 +516,26 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
516 | 516 | ||
517 | 517 | ||
518 | /** | 518 | /** |
519 | * Free memory associated with the work item from the work_finished map. | ||
520 | * | ||
521 | * @param cls NULL (unused) | ||
522 | * @param key key of the item in the map (unused) | ||
523 | * @param value the 'struct WorkItem' to free | ||
524 | * @return GNUNET_OK to continue to iterate | ||
525 | */ | ||
526 | static int | ||
527 | free_item (void *cls, | ||
528 | const struct GNUNET_HashCode *key, | ||
529 | void *value) | ||
530 | { | ||
531 | struct WorkItem *wi = value; | ||
532 | |||
533 | GNUNET_free (wi->filename); | ||
534 | GNUNET_free (wi); | ||
535 | return GNUNET_OK; | ||
536 | } | ||
537 | |||
538 | /** | ||
519 | * The main function to automatically publish content to GNUnet. | 539 | * The main function to automatically publish content to GNUnet. |
520 | * | 540 | * |
521 | * @param argc number of arguments from the command line | 541 | * @param argc number of arguments from the command line |
@@ -547,6 +567,7 @@ main (int argc, char *const *argv) | |||
547 | 0, &GNUNET_GETOPT_set_one, &verbose}, | 567 | 0, &GNUNET_GETOPT_set_one, &verbose}, |
548 | GNUNET_GETOPT_OPTION_END | 568 | GNUNET_GETOPT_OPTION_END |
549 | }; | 569 | }; |
570 | struct WorkItem *wi; | ||
550 | int ok; | 571 | int ok; |
551 | 572 | ||
552 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 573 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
@@ -556,7 +577,16 @@ main (int argc, char *const *argv) | |||
556 | gettext_noop | 577 | gettext_noop |
557 | ("Automatically publish files from a directory on GNUnet"), | 578 | ("Automatically publish files from a directory on GNUnet"), |
558 | options, &run, NULL)) ? ret : 1; | 579 | options, &run, NULL)) ? ret : 1; |
559 | // FIXME: free memory in work lists and hash map... | 580 | (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, |
581 | &free_item, | ||
582 | NULL); | ||
583 | GNUNET_CONTAINER_multihashmap_destroy (work_finished); | ||
584 | while (NULL != (wi = work_head)) | ||
585 | { | ||
586 | GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi); | ||
587 | GNUNET_free (wi->filename); | ||
588 | GNUNET_free (wi); | ||
589 | } | ||
560 | return ok; | 590 | return ok; |
561 | } | 591 | } |
562 | 592 | ||