Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding allocation site for double-free errors (with valgrind)

Tags:

linux

valgrind

Given a double-free error (reported by valgrind), is there a way to find out where the memory was allocated? Valgrind only tells me the location of the deallocation site (i.e. the call to free()), but I would like to know where the memory was allocated.

like image 302
JesperE Avatar asked Apr 14 '11 14:04

JesperE


1 Answers

To get Valgrind keep tracks of allocation stack traces, you have to use options:

--track-origins=yes --keep-stacktraces=alloc-and-free

Valgrind will then report allocation stack under Block was alloc'd at section, just after Address ... inside a block of size x free'd alert.

In case your application is large, --error-limit=no --num-callers=40 options may be useful too.

like image 198
Yves Martin Avatar answered Oct 13 '22 00:10

Yves Martin