Possible memory leak in Arena code
Opened this issue · 1 comments
GoogleCodeExporter commented
I think there's a memory leak in the Arena code.
Consider a scenario where:
* You create and release 3 arenas, each with a chunk of say 20KB of memory.
* You create a new arena, using one of those chunks; there are 2 chunks
left on the free list.
* You attempt to allocate a chunk of size 100KB.
If I read the code correctly, the loop in Arena_alloc() - p94 of the third
printing - invokes <get a new chunk 95>. Each time that is called, it
removes a chunk from the freelist, finds that it is not big enough, and
discards it, rather than restoring it to the freelist or releasing it.
--
Jonathan Leffler <jonathan.leffler@gmail.com>
Original issue reported on code.google.com by drhan...@gmail.com
on 29 Sep 2008 at 7:50
GoogleCodeExporter commented
I don't think there's a memory leak, but the code that allocates new chunks,
<get a
new check 95>, could certainly be improved.
The new check obtained in <ptr <- a new chunk 96>, whether allocated or taken
from
the free list, becomes the first chunk on the arena's list of chunks by virtue
of the
last 4 lines in <get a new chunk 95>.
Of course, *none* of this new chunk will be used when it's smaller than the
allocation request. Indeed, if the free list contains only chunks that are too
small,
*all* of them will be moved to the arena's list of chunks and none of them will
be
used! They will, however, be reclaimed when the arena is freed.
But it's obviously a waste to tie up chunks that aren't used. A better approach
would
be to search the free list for a chunk that *can* satisfy the allocation
request.
Original comment by drhan...@gmail.com
on 29 Sep 2008 at 7:58