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
--- a/settings.c	Tue Sep 20 15:19:28 2011 +0200
+++ b/settings.c	Thu Oct 06 00:06:30 2011 +0200
@@ -26,6 +26,6 @@
 }
 
 void destroy_settings_t(settings_t* settings) {
-  free(settings->suffixList);
+  destroy_suffix_list_t(settings->suffixList);
   free(settings);
 }
--- a/suffix_list.c	Tue Sep 20 15:19:28 2011 +0200
+++ b/suffix_list.c	Thu Oct 06 00:06:30 2011 +0200
@@ -15,9 +15,16 @@
   return suffixList;
 }
 
+void destroy_suffix_list_t(suffix_list_t* list) {
+  if (list->items != NULL) {
+    free(list->items);
+  }
+  free(list);
+}
+
 void add_suffix(suffix_list_t* list, char* item) {
   char** reallocated_list =
-    realloc(list->items, sizeof(char*) * list->count + 1);
+    realloc(list->items, sizeof(char*) * (list->count + 1));
   if (reallocated_list != NULL) {
     list->items = reallocated_list;
     list->items[list->count] = item;
--- a/suffix_list.h	Tue Sep 20 15:19:28 2011 +0200
+++ b/suffix_list.h	Thu Oct 06 00:06:30 2011 +0200
@@ -20,6 +20,7 @@
 #endif
 
 suffix_list_t* new_suffix_list_t();
+void destroy_suffix_list_t(suffix_list_t*);
 void add_suffix(suffix_list_t*, char*);
 
 #ifdef _cplusplus

mercurial