[pool] Uses memset() instead of assigning Null()

Assignment is invalid on invalid object.
This commit is contained in:
Behdad Esfahbod 2019-04-02 22:41:06 -07:00
parent 434d78bf91
commit 5efbc01174
1 changed files with 3 additions and 2 deletions

View File

@ -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;
}