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

View file

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