[Bug 276818] [libc] mtx_init memory leak

From: <bugzilla-noreply_at_freebsd.org>
Date: Sun, 04 Feb 2024 09:53:53 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=276818

Hodong <hodong@nimfsoft.art> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|mtx                         |[libc] mtx_init memory leak

--- Comment #1 from Hodong <hodong@nimfsoft.art> ---
Hello.
A memory leak occurs in mtx_init.

#include <threads.h>

int main ()
{
  mtx_t mtx;
  mtx_init (&mtx, mtx_plain);
  mtx_destroy (&mtx);
  return 0;
}

$ cc mtx.c -lstdthreads -o mtx

$ valgrind --leak-check=full ./mtx
==26748== Memcheck, a memory error detector
==26748== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==26748== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==26748== Command: ./mtx
==26748== 
==26748== 
==26748== HEAP SUMMARY:
==26748==     in use at exit: 1,748 bytes in 3 blocks
==26748==   total heap usage: 3 allocs, 0 frees, 1,748 bytes allocated
==26748== 
==26748== 20 bytes in 1 blocks are definitely lost in loss record 1 of 3
==26748==    at 0x484CDE4: malloc (vg_replace_malloc.c:446)
==26748==    by 0x4C791B2: pthread_mutexattr_init (in /lib/libthr.so.3)
==26748==    by 0x485EA9D: mtx_init (in /usr/lib/libstdthreads.so.0)
==26748==    by 0x2016FC: main (in /home/hodong/projects/snippets/mtx)
==26748== 
==26748== LEAK SUMMARY:
==26748==    definitely lost: 20 bytes in 1 blocks
==26748==    indirectly lost: 0 bytes in 0 blocks
==26748==      possibly lost: 0 bytes in 0 blocks
==26748==    still reachable: 1,728 bytes in 2 blocks
==26748==         suppressed: 0 bytes in 0 blocks
==26748== Reachable blocks (those to which a pointer was found) are not shown.
==26748== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==26748== 
==26748== For lists of detected and suppressed errors, rerun with: -s
==26748== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

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