fixed suffixList realloc bug + added destroy_suffix_list_t

Thu, 06 Oct 2011 00:06:30 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 06 Oct 2011 00:06:30 +0200
changeset 17
5f43f733cc12
parent 16
bc9a0fefd892
child 18
cae1294702aa

fixed suffixList realloc bug + added destroy_suffix_list_t

settings.c file | annotate | diff | comparison | revisions
suffix_list.c file | annotate | diff | comparison | revisions
suffix_list.h file | annotate | diff | comparison | revisions
     1.1 --- a/settings.c	Tue Sep 20 15:19:28 2011 +0200
     1.2 +++ b/settings.c	Thu Oct 06 00:06:30 2011 +0200
     1.3 @@ -26,6 +26,6 @@
     1.4  }
     1.5  
     1.6  void destroy_settings_t(settings_t* settings) {
     1.7 -  free(settings->suffixList);
     1.8 +  destroy_suffix_list_t(settings->suffixList);
     1.9    free(settings);
    1.10  }
     2.1 --- a/suffix_list.c	Tue Sep 20 15:19:28 2011 +0200
     2.2 +++ b/suffix_list.c	Thu Oct 06 00:06:30 2011 +0200
     2.3 @@ -15,9 +15,16 @@
     2.4    return suffixList;
     2.5  }
     2.6  
     2.7 +void destroy_suffix_list_t(suffix_list_t* list) {
     2.8 +  if (list->items != NULL) {
     2.9 +    free(list->items);
    2.10 +  }
    2.11 +  free(list);
    2.12 +}
    2.13 +
    2.14  void add_suffix(suffix_list_t* list, char* item) {
    2.15    char** reallocated_list =
    2.16 -    realloc(list->items, sizeof(char*) * list->count + 1);
    2.17 +    realloc(list->items, sizeof(char*) * (list->count + 1));
    2.18    if (reallocated_list != NULL) {
    2.19      list->items = reallocated_list;
    2.20      list->items[list->count] = item;
     3.1 --- a/suffix_list.h	Tue Sep 20 15:19:28 2011 +0200
     3.2 +++ b/suffix_list.h	Thu Oct 06 00:06:30 2011 +0200
     3.3 @@ -20,6 +20,7 @@
     3.4  #endif
     3.5  
     3.6  suffix_list_t* new_suffix_list_t();
     3.7 +void destroy_suffix_list_t(suffix_list_t*);
     3.8  void add_suffix(suffix_list_t*, char*);
     3.9  
    3.10  #ifdef _cplusplus

mercurial