This is a follow on from https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=276818 Using the same testcase I see two reachable allocations in Valgrind ==3215== 64 bytes in 1 blocks are still reachable in loss record 2 of 3 ==3215== at 0x48518C5: calloc (vg_replace_malloc.c:1601) ==3215== by 0x4C7C772: ??? (in /lib/libthr.so.3) ==3215== by 0x4C75385: ??? (in /lib/libthr.so.3) ==3215== by 0x4C743AE: ??? (in /lib/libthr.so.3) ==3215== by 0x400ABFC: ??? (in /libexec/ld-elf.so.1) ==3215== by 0x40098C8: ??? (in /libexec/ld-elf.so.1) ==3215== by 0x4006B88: ??? (in /libexec/ld-elf.so.1) ==3215== ==3215== 1,664 bytes in 1 blocks are still reachable in loss record 3 of 3 ==3215== at 0x48518C5: calloc (vg_replace_malloc.c:1601) ==3215== by 0x4C75374: ??? (in /lib/libthr.so.3) ==3215== by 0x4C743AE: ??? (in /lib/libthr.so.3) ==3215== by 0x400ABFC: ??? (in /libexec/ld-elf.so.1) ==3215== by 0x40098C8: ??? (in /libexec/ld-elf.so.1) ==3215== by 0x4006B88: ??? (in /libexec/ld-elf.so.1) First problem (for me) is that Valgrind isn't reading debuginfo so I'm not seeing file and line number. In gdb if I put breakpoints on those addresses I see that they are 4 breakpoint keep y 0x0000000004c75374 in _thr_alloc at /usr/src/lib/libthr/thread/thr_list.c:154 5 breakpoint keep y 0x0000000004c7c772 in _sleepq_alloc at /usr/src/lib/libthr/thread/thr_sleepq.c:66 For some reason gdb doesn't stop on the breakpoints. And if gdb can get file and line number then so should Valgrind. The allocations are if (thread == NULL) { if (total_threads > MAX_THREADS) return (NULL); atomic_fetchadd_int(&total_threads, 1); thread = calloc(1, sizeof(struct pthread)); if (thread == NULL) { atomic_fetchadd_int(&total_threads, -1); return (NULL); } if ((thread->sleepqueue = _sleepq_alloc()) == NULL || (thread->wake_addr = _thr_alloc_wake_addr()) == NULL) { thr_destroy(curthread, thread); atomic_fetchadd_int(&total_threads, -1); return (NULL); } and struct sleepqueue * _sleepq_alloc(void) { struct sleepqueue *sq; sq = calloc(1, sizeof(struct sleepqueue)); TAILQ_INIT(&sq->sq_blocked); SLIST_INIT(&sq->sq_freeq); return (sq); }
This is the userspace struct thread allocation (curthread) for main thread during initialization of the threading library. The memory is not supposed to be freed.
(In reply to Konstantin Belousov from comment #1) And the sleepqueue is the same? It would be nice to have a freeres function https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=259294 IKn the meantime I'll probably add a suppression.