Check if array destructor is NULL

This commit is contained in:
iabdalkader 2014-02-25 17:03:48 +02:00
parent 93d19a2e7d
commit 5a12d1e372
2 changed files with 5 additions and 3 deletions

View File

@ -27,10 +27,11 @@ void array_alloc(struct array **a, array_dtor dtor)
void array_free(struct array *array)
{
int i=0;
for (i=0; i<array->index; i++){
if (array->dtor != NULL) {
for (int i=0; i<array->index; i++){
array->dtor(array->data[i]);
}
}
xfree(array->data);
xfree(array);
}

View File

@ -5,6 +5,7 @@
#ifndef __ARRAY_H__
#define __ARRAY_H__
struct array;
typedef struct array array_t;
typedef void (*array_dtor)(void*);
typedef int (*array_comp)(const void*, const void*);
void array_alloc(struct array **array, array_dtor dtor);