More guarding against freeing NULL pointers.

This commit is contained in:
Omer Katz 2014-05-21 12:50:56 +03:00
parent 61b3b24e2e
commit 7303bc8f00
2 changed files with 21 additions and 16 deletions

View file

@ -25,6 +25,7 @@ void
list_free(l) list_free(l)
list *l; list *l;
{ {
if (l) {
list_item *li, *tmp; list_item *li, *tmp;
pthread_mutex_lock(&(l->mutex)); pthread_mutex_lock(&(l->mutex));
@ -33,7 +34,6 @@ list_free(l)
li = l->head; li = l->head;
while (li != NULL) { while (li != NULL) {
tmp = li->next; tmp = li->next;
zfree(li);
li = tmp; li = tmp;
} }
} }
@ -42,6 +42,7 @@ list_free(l)
pthread_mutex_destroy(&(l->mutex)); pthread_mutex_destroy(&(l->mutex));
zfree(l); zfree(l);
} }
}
list_item * list_item *
list_add_element(l, ptr) list_add_element(l, ptr)

View file

@ -21,12 +21,16 @@ str_array * str_array_create(int cap) {
} }
void str_array_free(str_array *l) { void str_array_free(str_array *l) {
if (l) {
for ( int i = 0; i < l->len ; i++ ) { for ( int i = 0; i < l->len ; i++ ) {
char * t = l->tokens[ i ]; char * t = l->tokens[ i ];
if (t) {
zfree(t); zfree(t);
} }
}
zfree(l); zfree(l);
} }
}
bool str_array_is_full(str_array * l) { bool str_array_is_full(str_array * l) {
return l->len >= l->cap; return l->len >= l->cap;