fix #16 #17: removed recursion from free_bloblist, added NULL checks.
authorKrista Grothoff <krista@pep-project.org>
Sun, 17 Jul 2016 16:52:31 +0200
changeset 8982d2bd8d77f5e
parent 897 1b478abf5b5a
child 899 ce7ae6e03713
fix #16 #17: removed recursion from free_bloblist, added NULL checks.
src/bloblist.c
     1.1 --- a/src/bloblist.c	Sun Jul 17 16:50:48 2016 +0200
     1.2 +++ b/src/bloblist.c	Sun Jul 17 16:52:31 2016 +0200
     1.3 @@ -41,13 +41,21 @@
     1.4  
     1.5  DYNAMIC_API void free_bloblist(bloblist_t *bloblist)
     1.6  {
     1.7 -    if (bloblist) {
     1.8 -        if (bloblist->next)
     1.9 -            free_bloblist(bloblist->next);
    1.10 -        free(bloblist->value);
    1.11 -        free(bloblist->mime_type);
    1.12 -        free(bloblist->filename);
    1.13 -        free(bloblist);
    1.14 +    bloblist_t *curr;
    1.15 +    bloblist_t *next;
    1.16 +    
    1.17 +    curr = bloblist;
    1.18 +    
    1.19 +    while (curr) {
    1.20 +        next = curr->next;
    1.21 +        if (curr->value)
    1.22 +            free(curr->value);
    1.23 +        if (curr->mime_type)
    1.24 +            free(curr->mime_type);
    1.25 +        if (curr->filename)
    1.26 +            free(curr->filename);
    1.27 +        free(curr);
    1.28 +        curr = next;
    1.29      }
    1.30  }
    1.31