Bug 31957

Summary: mcheck failed in multi-thread malloc/free test
Product: glibc Reporter: Miguel Martín <mmartinv>
Component: mallocAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: fweimer, mark
Priority: P2    
Version: unspecified   
Target Milestone: ---   
See Also: https://sourceware.org/bugzilla/show_bug.cgi?id=9939
Host: Target:
Build: Last reconfirmed:
Attachments: reproducer

Description Miguel Martín 2024-07-05 14:33:40 UTC
Created attachment 15602 [details]
reproducer

This problem was detected while creating new tests to enhance aligned_alloc/calloc/malloc test coverage (https://patchwork.sourceware.org/project/glibc/list/?series=35824)

A simplified reproducer is attached.

gcc -o threaded-malloc-free threaded-malloc-free.c ;
./threaded-malloc-free; echo $?
0

valgrind --tool=memcheck ./threaded-malloc-free 
==3433528== Memcheck, a memory error detector
==3433528== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==3433528== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==3433528== Command: ./threaded-malloc-free
==3433528== 
==3433528== 
==3433528== HEAP SUMMARY:
==3433528==     in use at exit: 0 bytes in 0 blocks
==3433528==   total heap usage: 131,147 allocs, 131,147 frees, 134,242,488 bytes allocated
==3433528== 
==3433528== All heap blocks were freed -- no leaks are possible
==3433528== 
==3433528== For lists of detected and suppressed errors, rerun with: -s
==3433528== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

gcc -o threaded-malloc-free threaded-malloc-free.c -lmcheck
LD_PRELOAD=/lib64/libc_malloc_debug.so.0 ./threaded-malloc-free; echo $?
memory clobbered before allocated block
memory clobbered before allocated block
Aborted (core dumped)
134
Comment 1 Florian Weimer 2024-07-05 15:34:46 UTC
Looks like a de-facto duplicate of bug 9939 to me. We don't do the problematic hook updates anymore, but there's still no lock protecting the allocation list in malloc/mcheck-impl.c.