Skip to content

Commit

Permalink
* mmap.c (backtrace_free_locked): Don't put more than 16 entries
Browse files Browse the repository at this point in the history
	on the free list.

Fixes #5
Fixes rust-lang/rust#29293
Fixes rust-lang/rust#37477
  • Loading branch information
ianlancetaylor committed Jan 25, 2018
1 parent 3739537 commit b0d6903
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,33 @@ struct backtrace_freelist_struct
static void
backtrace_free_locked (struct backtrace_state *state, void *addr, size_t size)
{
/* Just leak small blocks. We don't have to be perfect. */
/* Just leak small blocks. We don't have to be perfect. Don't put
more than 16 entries on the free list, to avoid wasting time
searching when allocating a block. If we have more than 16
entries, leak the smallest entry. */

if (size >= sizeof (struct backtrace_freelist_struct))
{
size_t c;
struct backtrace_freelist_struct **ppsmall;
struct backtrace_freelist_struct **pp;
struct backtrace_freelist_struct *p;

c = 0;
ppsmall = NULL;
for (pp = &state->freelist; *pp != NULL; pp = &(*pp)->next)
{
if (ppsmall == NULL || (*pp)->size < (*ppsmall)->size)
ppsmall = pp;
++c;
}
if (c >= 16)
{
if (size <= (*ppsmall)->size)
return;
*ppsmall = (*ppsmall)->next;
}

p = (struct backtrace_freelist_struct *) addr;
p->next = state->freelist;
p->size = size;
Expand Down

0 comments on commit b0d6903

Please sign in to comment.