NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/59189: leak sanitizer broken



>Number:         59189
>Category:       toolchain
>Synopsis:       leak sanitizer broken
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 17 14:10:00 +0000 2025
>Originator:     Thomas Klausner
>Release:        NetBSD 10.99.12
>Organization:
	
>Environment:
	
	
Architecture: x86_64
Machine: amd64
>Description:
The leak sanitizer is broken on -current.

On NetBSD 10, the program below (from riastradh) does:

# make lsanthread DBG=-g\ -O2\ -Wall\ -Werror\ -fsanitize=leak LDLIBS=-pthread
cc -g -O2 -Wall -Werror -fsanitize=leak    -o lsanthread lsanthread.c -pthread
# ./lsanthread

=================================================================
==9052==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 2 byte(s) in 2 object(s) allocated from:
    #0 0x75d53c005d27 in __interceptor_malloc /usr/src/external/gpl3/gcc/dist/libsanitizer/lsan/lsan_interceptors.cc:53
    #1 0x400abb in thread /home/wiz/lsanthread.c:14
    #2 0x75d53bc0c89e in pthread__create_tramp /usr/src/lib/libpthread/pthread.c:595

SUMMARY: LeakSanitizer: 2 byte(s) leaked in 2 allocation(s).

while on NetBSD 10.99.12, it does

# make lsanthread DBG=-g\ -O2\ -Wall\ -Werror\ -fsanitize=leak LDLIBS=-pthread
cc -g -O2 -Wall -Werror -fsanitize=leak    -o lsanthread lsanthread.c -pthread
ld: /usr/lib/libm.so.0: warning: warning: reference to compatibility cabs()
ld: /usr/lib/libm.so.0: warning: warning: reference to compatibility cabsf()
# ./lsanthread
zsh: segmentation fault (core dumped)  ./lsanthread

Here's the program:

/*
 * make lsanthread DBG=-g\ -O2\ -Wall\ -Werror\ -fsanitize=leak LDLIBS=-pthread
 */

#include <err.h>
#include <pthread.h>
#include <stdlib.h>

static void *
thread(void *cookie)
{
	void *volatile p;

	p = malloc(1);
	p = NULL;

	return p;
}

int
main(void)
{
	pthread_t t[2];
	void *result;
	unsigned i;
	int error;

	for (i = 0; i < __arraycount(t); i++) {
		error = pthread_create(&t[i], NULL, &thread, NULL);
		if (error)
			errc(1, error, "pthread_create");
	}
	for (i = 0; i < __arraycount(t); i++) {
		error = pthread_join(t[i], &result);
		if (error)
			errc(1, error, "pthread_join");
	}

	return 0;
}

>How-To-Repeat:
See above.
>Fix:
Yes, please, and please add tests so this doesn't break again, unnoticed.

>Unformatted:
 	
 	


Home | Main Index | Thread Index | Old Index