File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -69,11 +69,33 @@ struct backtrace_freelist_struct
69
69
static void
70
70
backtrace_free_locked (struct backtrace_state * state , void * addr , size_t size )
71
71
{
72
- /* Just leak small blocks. We don't have to be perfect. */
72
+ /* Just leak small blocks. We don't have to be perfect. Don't put
73
+ more than 16 entries on the free list, to avoid wasting time
74
+ searching when allocating a block. If we have more than 16
75
+ entries, leak the smallest entry. */
76
+
73
77
if (size >= sizeof (struct backtrace_freelist_struct ))
74
78
{
79
+ size_t c ;
80
+ struct backtrace_freelist_struct * * ppsmall ;
81
+ struct backtrace_freelist_struct * * pp ;
75
82
struct backtrace_freelist_struct * p ;
76
83
84
+ c = 0 ;
85
+ ppsmall = NULL ;
86
+ for (pp = & state -> freelist ; * pp != NULL ; pp = & (* pp )-> next )
87
+ {
88
+ if (ppsmall == NULL || (* pp )-> size < (* ppsmall )-> size )
89
+ ppsmall = pp ;
90
+ ++ c ;
91
+ }
92
+ if (c >= 16 )
93
+ {
94
+ if (size <= (* ppsmall )-> size )
95
+ return ;
96
+ * ppsmall = (* ppsmall )-> next ;
97
+ }
98
+
77
99
p = (struct backtrace_freelist_struct * ) addr ;
78
100
p -> next = state -> freelist ;
79
101
p -> size = size ;
You can’t perform that action at this time.
0 commit comments