From 5efbc01174127bede4d533866acac239e5a0cfd5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Apr 2019 22:41:06 -0700 Subject: [PATCH] [pool] Uses memset() instead of assigning Null() Assignment is invalid on invalid object. --- src/hb-pool.hh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hb-pool.hh b/src/hb-pool.hh index 7e49ad0..5f54d8c 100644 --- a/src/hb-pool.hh +++ b/src/hb-pool.hh @@ -39,6 +39,7 @@ struct hb_pool_t ~hb_pool_t () { next = nullptr; + + hb_iter (chunks) | hb_apply ([] (chunk_t *_) { ::free (_); }) ; @@ -49,7 +50,7 @@ struct hb_pool_t if (unlikely (!next)) { if (unlikely (!chunks.alloc (chunks.length + 1))) return nullptr; - chunk_t *chunk = (chunk_t *) malloc (sizeof (chunk_t)); + chunk_t *chunk = (chunk_t *) calloc (1, sizeof (chunk_t)); if (unlikely (!chunk)) return nullptr; chunks.push (chunk); next = chunk->thread (); @@ -58,7 +59,7 @@ struct hb_pool_t T* obj = next; next = * ((T**) next); - *obj = Null (T); + memset (obj, 0, sizeof (T)); return obj; } -- 2.7.4