diff options
Diffstat (limited to 'libdimension/dimension/array.h')
-rw-r--r-- | libdimension/dimension/array.h | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/libdimension/dimension/array.h b/libdimension/dimension/array.h index d962d42..1b3771d 100644 --- a/libdimension/dimension/array.h +++ b/libdimension/dimension/array.h @@ -36,6 +36,16 @@ typedef struct { size_t obj_size, length, capacity; } dmnsn_array; +/* Delete an array */ +DMNSN_INLINE void +dmnsn_delete_array(dmnsn_array *array) +{ + if (array) { + free(array->ptr); + free(array); + } +} + /* Array allocation never returns NULL - if dmnsn_new_array returns, it succeeded */ DMNSN_INLINE dmnsn_array * @@ -50,6 +60,7 @@ dmnsn_new_array(size_t obj_size) /* Allocate the memory */ array->ptr = malloc(array->capacity*array->obj_size); if (!array->ptr) { + dmnsn_delete_array(array); dmnsn_error(DMNSN_SEVERITY_HIGH, "Array allocation failed."); } } else { @@ -59,16 +70,6 @@ dmnsn_new_array(size_t obj_size) return array; } -/* Delete the array */ -DMNSN_INLINE void -dmnsn_delete_array(dmnsn_array *array) -{ - if (array) { - free(array->ptr); - free(array); - } -} - /* Get the size of the array */ DMNSN_INLINE size_t dmnsn_array_size(const dmnsn_array *array) |