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,22 +25,23 @@ void
list_free(l) list_free(l)
list *l; list *l;
{ {
list_item *li, *tmp; if (l) {
list_item *li, *tmp;
pthread_mutex_lock(&(l->mutex)); pthread_mutex_lock(&(l->mutex));
if (l != NULL) { if (l != NULL) {
li = l->head; li = l->head;
while (li != NULL) { while (li != NULL) {
tmp = li->next; tmp = li->next;
zfree(li); li = tmp;
li = tmp; }
} }
}
pthread_mutex_unlock(&(l->mutex)); pthread_mutex_unlock(&(l->mutex));
pthread_mutex_destroy(&(l->mutex)); pthread_mutex_destroy(&(l->mutex));
zfree(l); zfree(l);
}
} }
list_item * list_item *

View file

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