File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 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
6969static void
7070backtrace_free_locked (struct backtrace_state * state , void * addr , size_t size )
7171{
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+
7377 if (size >= sizeof (struct backtrace_freelist_struct ))
7478 {
79+ size_t c ;
80+ struct backtrace_freelist_struct * * ppsmall ;
81+ struct backtrace_freelist_struct * * pp ;
7582 struct backtrace_freelist_struct * p ;
7683
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+
7799 p = (struct backtrace_freelist_struct * ) addr ;
78100 p -> next = state -> freelist ;
79101 p -> size = size ;
You can’t perform that action at this time.
0 commit comments