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

View File

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