HuntnGather
/trunk/HuntnGather/Gather/StringStack.c |
@@ -31,8 +31,11 @@ |
stringStack* stringStackCreate(unsigned int size) { |
stringStack *s; |
s = malloc(sizeof(*s)); |
if ((s->store = malloc(size * sizeof(*s->store))) == NULL) |
if ((s->store = malloc(size * sizeof(*s->store))) == NULL) { |
free(s); |
s = NULL; |
return NULL; |
} |
s->size = size; |
s->top = 0; |
return s; |
@@ -42,8 +45,10 @@ |
* Clears a stringStack and returns a pointer to a new empty stack. |
*/ |
stringStack* stringStackClear(stringStack *s) { |
if (s != NULL) |
if (s != NULL) { |
free(s); |
s = NULL; |
} |
return stringStackCreate(1); |
} |
|
@@ -70,6 +75,7 @@ |
e = malloc((strlen(s->store[s->top]) + 1) * sizeof(*e)); |
strncpy(e, s->store[s->top], strlen(s->store[s->top]) + 1); |
free(s->store[s->top]); |
s->store[s->top] = NULL; |
return e; |
} |
|
@@ -81,8 +87,10 @@ |
while(!stringStackIsEmpty(s)) { |
e = stringStackPop(s); |
free(e); |
e = NULL; |
} |
free(s); |
s = NULL; |
} |
|
/* |