[PATCH] sandbox: add memory leak debugging tooling around LeakSanitizer

Sascha Hauer s.hauer at pengutronix.de
Fri Nov 7 05:24:05 PST 2025


On Tue, Oct 28, 2025 at 08:59:05AM +0100, Ahmad Fatoum wrote:
> Hi Sascha,
> 
> On 10/28/25 8:57 AM, Sascha Hauer wrote:
> > On Mon, Oct 27, 2025 at 08:44:45AM +0100, Ahmad Fatoum wrote:
> >> When enabled, this allows calling barebox_memleak_check() or running the
> >> checkleak command to instruct LeakSanitizer to sweep the memory and find
> >> unreferenced allocations.
> >>
> >> LeakSanitizier is also enabled along AddressSanitizer and runs on AMD64
> >> Linux automatically on exit already.
> >>
> >> +static int do_checkleak(int argc, char *argv[])
> >> +{
> >> +	unsigned int count;
> >> +	int opt;
> >> +
> >> +	while((opt = getopt(argc, argv, "l:")) > 0) {
> >> +		switch(opt) {
> >> +		case 'l':
> >> +			if (kstrtouint(optarg, 0, &count))
> >> +				return COMMAND_ERROR;
> >> +			(void)malloc(count);
> >> +			break;
> >> +		default:
> >> +			return COMMAND_ERROR_USAGE;
> >> +		}
> >> +	}
> >> +
> >> +	argv += optind;
> >> +	argc -= optind;
> >> +
> >> +	if (argc)
> >> +		return COMMAND_ERROR_USAGE;
> >> +
> >> +	memleak_check();
> > 
> > barebox exits in this call. Is this intended?
> 
> Until I figure out how to suppress it, yes, unfortunately. Haven't dug
> into the source code yet.

With __lsan_do_recoverable_leak_check() instead of
__lsan_do_leak_check() the progam doesn't exit.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list