summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/nxt_array.c15
-rw-r--r--src/nxt_array.h1
2 files changed, 15 insertions, 1 deletions
diff --git a/src/nxt_array.c b/src/nxt_array.c
index f26670f5..82019f92 100644
--- a/src/nxt_array.c
+++ b/src/nxt_array.c
@@ -28,6 +28,17 @@ nxt_array_create(nxt_mp_t *mp, nxt_uint_t n, size_t size)
}
+void
+nxt_array_destroy(nxt_array_t *array)
+{
+ if (array->elts != nxt_pointer_to(array, sizeof(nxt_array_t))) {
+ nxt_mp_free(array->mem_pool, array->elts);
+ }
+
+ nxt_mp_free(array->mem_pool, array);
+}
+
+
void *
nxt_array_add(nxt_array_t *array)
{
@@ -55,7 +66,9 @@ nxt_array_add(nxt_array_t *array)
nxt_memcpy(p, array->elts, array->size * nalloc);
- nxt_mp_free(array->mem_pool, array->elts);
+ if (array->elts != nxt_pointer_to(array, sizeof(nxt_array_t))) {
+ nxt_mp_free(array->mem_pool, array->elts);
+ }
array->elts = p;
array->nalloc = new_alloc;
diff --git a/src/nxt_array.h b/src/nxt_array.h
index 8a99aa2c..8d2b14f1 100644
--- a/src/nxt_array.h
+++ b/src/nxt_array.h
@@ -20,6 +20,7 @@ typedef struct {
NXT_EXPORT nxt_array_t *nxt_array_create(nxt_mp_t *mp, nxt_uint_t n,
size_t size);
+NXT_EXPORT void nxt_array_destroy(nxt_array_t *array);
NXT_EXPORT void *nxt_array_add(nxt_array_t *array);
NXT_EXPORT void *nxt_array_zero_add(nxt_array_t *array);
NXT_EXPORT void nxt_array_remove(nxt_array_t *array, void *elt);