diff options
author | Alex Lapenkou <lapenkov@fb.com> | 2021-10-06 15:22:38 -0700 |
---|---|---|
committer | Alexander Lapenkov <lapenkov.a@yandex.ru> | 2021-10-07 11:50:38 -0700 |
commit | c9ebff0fd6ab90d5eed0d11f48dfedcc21222ab0 (patch) | |
tree | ffcf57e55bb63c35f6f143bc8280e4e21a2ea361 /test | |
parent | 912324a1acae4bfb6445825caad000aa295dcca8 (diff) | |
download | jemalloc-c9ebff0fd6ab90d5eed0d11f48dfedcc21222ab0.tar.gz |
Initialize deferred_work_generated
As the code evolves, some code paths that have previously assigned
deferred_work_generated may cease being reached. This would leave the value
uninitialized. This change initializes the value for safety.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/hpa.c | 8 | ||||
-rw-r--r-- | test/unit/pa.c | 2 | ||||
-rw-r--r-- | test/unit/sec.c | 24 |
3 files changed, 14 insertions, 20 deletions
diff --git a/test/unit/hpa.c b/test/unit/hpa.c index 060ce3e4..bda0d46d 100644 --- a/test/unit/hpa.c +++ b/test/unit/hpa.c @@ -79,7 +79,7 @@ TEST_BEGIN(test_alloc_max) { edata_t *edata; /* Small max */ - bool deferred_work_generated; + bool deferred_work_generated = false; edata = pai_alloc(tsdn, &shard->pai, ALLOC_MAX, PAGE, false, false, &deferred_work_generated); expect_ptr_not_null(edata, "Allocation of small max failed"); @@ -169,7 +169,7 @@ TEST_BEGIN(test_stress) { mem_tree_t tree; mem_tree_new(&tree); - bool deferred_work_generated; + bool deferred_work_generated = false; for (size_t i = 0; i < 100 * 1000; i++) { size_t operation = prng_range_zu(&prng_state, 2); @@ -252,7 +252,7 @@ TEST_BEGIN(test_alloc_dalloc_batch) { &test_hpa_shard_opts_default); tsdn_t *tsdn = tsd_tsdn(tsd_fetch()); - bool deferred_work_generated; + bool deferred_work_generated = false; enum {NALLOCS = 8}; @@ -369,7 +369,7 @@ TEST_BEGIN(test_defer_time) { hpa_shard_t *shard = create_test_data(&hooks, &opts); - bool deferred_work_generated; + bool deferred_work_generated = false; nstime_init(&defer_curtime, 0); tsdn_t *tsdn = tsd_tsdn(tsd_fetch()); diff --git a/test/unit/pa.c b/test/unit/pa.c index 10fa1b28..505b6fa9 100644 --- a/test/unit/pa.c +++ b/test/unit/pa.c @@ -88,7 +88,7 @@ static void * do_alloc_free_purge(void *arg) { test_data_t *test_data = (test_data_t *)arg; for (int i = 0; i < 10 * 1000; i++) { - bool deferred_work_generated; + bool deferred_work_generated = false; edata_t *edata = pa_alloc(TSDN_NULL, &test_data->shard, PAGE, PAGE, /* slab */ false, /* szind */ 0, /* zero */ false, /* guarded */ false, &deferred_work_generated); diff --git a/test/unit/sec.c b/test/unit/sec.c index acca192d..8ac3411c 100644 --- a/test/unit/sec.c +++ b/test/unit/sec.c @@ -54,7 +54,6 @@ pai_test_allocator_alloc(tsdn_t *tsdn, pai_t *self, size_t size, bool *deferred_work_generated) { assert(!guarded); pai_test_allocator_t *ta = (pai_test_allocator_t *)self; - *deferred_work_generated = false; if (ta->alloc_fail) { return NULL; } @@ -76,7 +75,6 @@ pai_test_allocator_alloc_batch(tsdn_t *tsdn, pai_t *self, size_t size, size_t nallocs, edata_list_active_t *results, bool *deferred_work_generated) { pai_test_allocator_t *ta = (pai_test_allocator_t *)self; - *deferred_work_generated = false; if (ta->alloc_fail) { return 0; } @@ -100,7 +98,6 @@ pai_test_allocator_expand(tsdn_t *tsdn, pai_t *self, edata_t *edata, size_t old_size, size_t new_size, bool zero, bool *deferred_work_generated) { pai_test_allocator_t *ta = (pai_test_allocator_t *)self; - *deferred_work_generated = false; ta->expand_count++; return ta->expand_return_value; } @@ -109,7 +106,6 @@ static bool pai_test_allocator_shrink(tsdn_t *tsdn, pai_t *self, edata_t *edata, size_t old_size, size_t new_size, bool *deferred_work_generated) { pai_test_allocator_t *ta = (pai_test_allocator_t *)self; - *deferred_work_generated = false; ta->shrink_count++; return ta->shrink_return_value; } @@ -118,7 +114,6 @@ static void pai_test_allocator_dalloc(tsdn_t *tsdn, pai_t *self, edata_t *edata, bool *deferred_work_generated) { pai_test_allocator_t *ta = (pai_test_allocator_t *)self; - *deferred_work_generated = false; ta->dalloc_count++; free(edata); } @@ -127,7 +122,6 @@ static void pai_test_allocator_dalloc_batch(tsdn_t *tsdn, pai_t *self, edata_list_active_t *list, bool *deferred_work_generated) { pai_test_allocator_t *ta = (pai_test_allocator_t *)self; - *deferred_work_generated = false; edata_t *edata; while ((edata = edata_list_active_first(list)) != NULL) { @@ -179,7 +173,7 @@ TEST_BEGIN(test_reuse) { enum { NALLOCS = 11 }; edata_t *one_page[NALLOCS]; edata_t *two_page[NALLOCS]; - bool deferred_work_generated; + bool deferred_work_generated = false; test_sec_init(&sec, &ta.pai, /* nshards */ 1, /* max_alloc */ 2 * PAGE, /* max_bytes */ 2 * (NALLOCS * PAGE + NALLOCS * 2 * PAGE)); for (int i = 0; i < NALLOCS; i++) { @@ -256,7 +250,7 @@ TEST_BEGIN(test_auto_flush) { enum { NALLOCS = 10 }; edata_t *extra_alloc; edata_t *allocs[NALLOCS]; - bool deferred_work_generated; + bool deferred_work_generated = false; test_sec_init(&sec, &ta.pai, /* nshards */ 1, /* max_alloc */ PAGE, /* max_bytes */ NALLOCS * PAGE); for (int i = 0; i < NALLOCS; i++) { @@ -312,7 +306,7 @@ do_disable_flush_test(bool is_disable) { enum { NALLOCS = 11 }; edata_t *allocs[NALLOCS]; - bool deferred_work_generated; + bool deferred_work_generated = false; test_sec_init(&sec, &ta.pai, /* nshards */ 1, /* max_alloc */ PAGE, /* max_bytes */ NALLOCS * PAGE); for (int i = 0; i < NALLOCS; i++) { @@ -380,7 +374,7 @@ TEST_BEGIN(test_max_alloc_respected) { size_t max_alloc = 2 * PAGE; size_t attempted_alloc = 3 * PAGE; - bool deferred_work_generated; + bool deferred_work_generated = false; test_sec_init(&sec, &ta.pai, /* nshards */ 1, max_alloc, /* max_bytes */ 1000 * PAGE); @@ -414,7 +408,7 @@ TEST_BEGIN(test_expand_shrink_delegate) { /* See the note above -- we can't use the real tsd. */ tsdn_t *tsdn = TSDN_NULL; - bool deferred_work_generated; + bool deferred_work_generated = false; test_sec_init(&sec, &ta.pai, /* nshards */ 1, /* max_alloc */ 10 * PAGE, /* max_bytes */ 1000 * PAGE); @@ -458,7 +452,7 @@ TEST_BEGIN(test_nshards_0) { opts.nshards = 0; sec_init(TSDN_NULL, &sec, base, &ta.pai, &opts); - bool deferred_work_generated; + bool deferred_work_generated = false; edata_t *edata = pai_alloc(tsdn, &sec.pai, PAGE, PAGE, /* zero */ false, /* guarded */ false, &deferred_work_generated); @@ -495,7 +489,7 @@ TEST_BEGIN(test_stats_simple) { FLUSH_PAGES = 20, }; - bool deferred_work_generated; + bool deferred_work_generated = false; test_sec_init(&sec, &ta.pai, /* nshards */ 1, /* max_alloc */ PAGE, /* max_bytes */ FLUSH_PAGES * PAGE); @@ -544,7 +538,7 @@ TEST_BEGIN(test_stats_auto_flush) { edata_t *extra_alloc1; edata_t *allocs[2 * FLUSH_PAGES]; - bool deferred_work_generated; + bool deferred_work_generated = false; extra_alloc0 = pai_alloc(tsdn, &sec.pai, PAGE, PAGE, /* zero */ false, /* guarded */ false, &deferred_work_generated); @@ -590,7 +584,7 @@ TEST_BEGIN(test_stats_manual_flush) { test_sec_init(&sec, &ta.pai, /* nshards */ 1, /* max_alloc */ PAGE, /* max_bytes */ FLUSH_PAGES * PAGE); - bool deferred_work_generated; + bool deferred_work_generated = false; edata_t *allocs[FLUSH_PAGES]; for (size_t i = 0; i < FLUSH_PAGES; i++) { allocs[i] = pai_alloc(tsdn, &sec.pai, PAGE, PAGE, |