Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak in Arena code #1

Open
GoogleCodeExporter opened this issue Mar 23, 2015 · 1 comment
Open

Possible memory leak in Arena code #1

GoogleCodeExporter opened this issue Mar 23, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant