[Bug 277065] [libthr] reachable memory

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 15 Feb 2024 12:31:35 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277065

            Bug ID: 277065
           Summary: [libthr] reachable memory
           Product: Base System
           Version: 14.0-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: threads
          Assignee: threads@FreeBSD.org
          Reporter: pjfloyd@wanadoo.fr

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);
}

-- 
You are receiving this mail because:
You are the assignee for the bug.