aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2017-04-27 15:51:35 -0700
committerJason Evans <jasone@canonware.com>2017-04-29 09:24:12 -0700
commitc86c8f4ffbf8c118203f7327610a2ad80cf9622c (patch)
tree88d2dd9f195a744e2da0f1f1cad9f718abd7872f /test
parentb9ab04a191dbcb9246d5180fc7ae822a85861939 (diff)
downloadplatform_external_jemalloc_new-c86c8f4ffbf8c118203f7327610a2ad80cf9622c.tar.gz
platform_external_jemalloc_new-c86c8f4ffbf8c118203f7327610a2ad80cf9622c.tar.bz2
platform_external_jemalloc_new-c86c8f4ffbf8c118203f7327610a2ad80cf9622c.zip
Add extent_destroy_t and use it during arena destruction.
Add the extent_destroy_t extent destruction hook to extent_hooks_t, and use it during arena destruction. This hook explicitly communicates to the callee that the extent must be destroyed or tracked for later reuse, lest it be permanently leaked. Prior to this change, retained extents could unintentionally be leaked if extent retention was enabled. This resolves #560.
Diffstat (limited to 'test')
-rw-r--r--test/include/test/extent_hooks.h24
-rw-r--r--test/unit/arena_reset.c1
-rw-r--r--test/unit/base.c8
3 files changed, 32 insertions, 1 deletions
diff --git a/test/include/test/extent_hooks.h b/test/include/test/extent_hooks.h
index 96fee103..ea012857 100644
--- a/test/include/test/extent_hooks.h
+++ b/test/include/test/extent_hooks.h
@@ -8,6 +8,8 @@ static void *extent_alloc_hook(extent_hooks_t *extent_hooks, void *new_addr,
unsigned arena_ind);
static bool extent_dalloc_hook(extent_hooks_t *extent_hooks, void *addr,
size_t size, bool committed, unsigned arena_ind);
+static void extent_destroy_hook(extent_hooks_t *extent_hooks, void *addr,
+ size_t size, bool committed, unsigned arena_ind);
static bool extent_commit_hook(extent_hooks_t *extent_hooks, void *addr,
size_t size, size_t offset, size_t length, unsigned arena_ind);
static bool extent_decommit_hook(extent_hooks_t *extent_hooks, void *addr,
@@ -27,6 +29,7 @@ static extent_hooks_t *default_hooks;
static extent_hooks_t hooks = {
extent_alloc_hook,
extent_dalloc_hook,
+ extent_destroy_hook,
extent_commit_hook,
extent_decommit_hook,
extent_purge_lazy_hook,
@@ -38,6 +41,7 @@ static extent_hooks_t hooks = {
/* Control whether hook functions pass calls through to default hooks. */
static bool try_alloc = true;
static bool try_dalloc = true;
+static bool try_destroy = true;
static bool try_commit = true;
static bool try_decommit = true;
static bool try_purge_lazy = true;
@@ -48,6 +52,7 @@ static bool try_merge = true;
/* Set to false prior to operations, then introspect after operations. */
static bool called_alloc;
static bool called_dalloc;
+static bool called_destroy;
static bool called_commit;
static bool called_decommit;
static bool called_purge_lazy;
@@ -58,6 +63,7 @@ static bool called_merge;
/* Set to false prior to operations, then introspect after operations. */
static bool did_alloc;
static bool did_dalloc;
+static bool did_destroy;
static bool did_commit;
static bool did_decommit;
static bool did_purge_lazy;
@@ -115,6 +121,24 @@ extent_dalloc_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
return err;
}
+static void
+extent_destroy_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
+ bool committed, unsigned arena_ind) {
+ TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, committed=%s, "
+ "arena_ind=%u)\n", __func__, extent_hooks, addr, size, committed ?
+ "true" : "false", arena_ind);
+ assert_ptr_eq(extent_hooks, &hooks,
+ "extent_hooks should be same as pointer used to set hooks");
+ assert_ptr_eq(extent_hooks->destroy, extent_destroy_hook,
+ "Wrong hook function");
+ called_destroy = true;
+ if (!try_destroy) {
+ return;
+ }
+ default_hooks->destroy(default_hooks, addr, size, committed, 0);
+ did_destroy = true;
+}
+
static bool
extent_commit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
size_t offset, size_t length, unsigned arena_ind) {
diff --git a/test/unit/arena_reset.c b/test/unit/arena_reset.c
index 5d6c1a77..d1698325 100644
--- a/test/unit/arena_reset.c
+++ b/test/unit/arena_reset.c
@@ -278,6 +278,7 @@ static extent_hooks_t hooks_orig;
static extent_hooks_t hooks_unmap = {
extent_alloc_hook,
extent_dalloc_unmap, /* dalloc */
+ extent_destroy_hook,
extent_commit_hook,
extent_decommit_hook,
extent_purge_lazy_hook,
diff --git a/test/unit/base.c b/test/unit/base.c
index f498394e..5dc42f0a 100644
--- a/test/unit/base.c
+++ b/test/unit/base.c
@@ -5,6 +5,7 @@
static extent_hooks_t hooks_null = {
extent_alloc_hook,
NULL, /* dalloc */
+ NULL, /* destroy */
NULL, /* commit */
NULL, /* decommit */
NULL, /* purge_lazy */
@@ -16,6 +17,7 @@ static extent_hooks_t hooks_null = {
static extent_hooks_t hooks_not_null = {
extent_alloc_hook,
extent_dalloc_hook,
+ extent_destroy_hook,
NULL, /* commit */
extent_decommit_hook,
extent_purge_lazy_hook,
@@ -59,6 +61,7 @@ TEST_BEGIN(test_base_hooks_null) {
extent_hooks_prep();
try_dalloc = false;
+ try_destroy = true;
try_decommit = false;
try_purge_lazy = false;
try_purge_forced = false;
@@ -98,6 +101,7 @@ TEST_BEGIN(test_base_hooks_not_null) {
extent_hooks_prep();
try_dalloc = false;
+ try_destroy = true;
try_decommit = false;
try_purge_lazy = false;
try_purge_forced = false;
@@ -194,15 +198,17 @@ TEST_BEGIN(test_base_hooks_not_null) {
}
}
- called_dalloc = called_decommit = called_purge_lazy =
+ called_dalloc = called_destroy = called_decommit = called_purge_lazy =
called_purge_forced = false;
base_delete(base);
assert_true(called_dalloc, "Expected dalloc call");
+ assert_true(!called_destroy, "Unexpected destroy call");
assert_true(called_decommit, "Expected decommit call");
assert_true(called_purge_lazy, "Expected purge_lazy call");
assert_true(called_purge_forced, "Expected purge_forced call");
try_dalloc = true;
+ try_destroy = true;
try_decommit = true;
try_purge_lazy = true;
try_purge_forced = true;