diff options
author | Max Romanov <max.romanov@nginx.com> | 2017-07-12 20:32:22 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2017-07-12 20:32:22 +0300 |
commit | 288fa854315067b66cc5926222e0bfb5942147a2 (patch) | |
tree | 205147b5a5b27792f4bcb34274e27123ac86024f | |
parent | 48afadfe7c617991cefc289e0200bfbbadecdbb9 (diff) | |
download | unit-288fa854315067b66cc5926222e0bfb5942147a2.tar.gz unit-288fa854315067b66cc5926222e0bfb5942147a2.tar.bz2 |
Array elements reallocation fixed.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_array.c | 15 | ||||
-rw-r--r-- | src/nxt_array.h | 1 |
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); |