public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Parthiban <parthiban@linumiz.com>
To: libc-help@sourceware.org
Cc: Parthiban <parthiban@linumiz.com>
Subject: glibc mq_notify memory leak report
Date: Mon, 9 Jan 2023 20:43:13 +0530	[thread overview]
Message-ID: <abe21391-8d9f-4035-f0a5-d4f8a1a7d83f@linumiz.com> (raw)

Dear All,

I have the following code snippet and `mq_close`, `mq_unlink` is called in exit path.
But with valgrind, I have the summary about possibly lost.

How to gracefully remove the notification during exit path?

From man mq_close,
If  the  calling process has attached a notification request (see (mq_notify(3)) to this
message queue via mqdes, then this request is removed

Valgrind summary:
```
==381555== HEAP SUMMARY:
==381555==     in use at exit: 5,716 bytes in 13 blocks                                                                                                       
==381555==   total heap usage: 39,786 allocs, 39,773 frees, 267,728,707 bytes allocated
==381555==                                                                                                                                                    
==381555== Thread 1:
==381555== 304 bytes in 1 blocks are possibly lost in loss record 3 of 5      
==381555==    at 0x4846A73: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==381555==    by 0x4011282: calloc (rtld-malloc.h:44)                                                                                                         
==381555==    by 0x4011282: allocate_dtv (dl-tls.c:375)                       
==381555==    by 0x4011C91: _dl_allocate_tls (dl-tls.c:634)
==381555==    by 0x4F244DF: allocate_stack (allocatestack.c:423)
==381555==    by 0x4F244DF: pthread_create@@GLIBC_2.34 (pthread_create.c:650)
==381555==    by 0x4F2E70E: init_mq_netlink (mq_notify.c:183)                
==381555==    by 0x4F28886: __pthread_once_slow (pthread_once.c:116)         
==381555==    by 0x4F2E802: __mq_notify (mq_notify.c:219)           
==381555==    by 0x4F2E802: mq_notify@@GLIBC_2.34 (mq_notify.c:203) 
==381555==    by 0x10C3D1: mq_notify_init (upstream.c:201)         
==381555==    by 0x10E306: mq_handler_init (upstream.c:1019)       
==381555==    by 0x10EDB6: upstream_init_async (upstream.c:1244)
==381555==    by 0x10BFD6: main (main.c:83)                     
==381555==                                                                     
==381555== LEAK SUMMARY:                                                      
==381555==    definitely lost: 0 bytes in 0 blocks                            
==381555==    indirectly lost: 0 bytes in 0 blocks                            
==381555==      possibly lost: 304 bytes in 1 blocks
==381555==    still reachable: 5,412 bytes in 12 blocks
==381555==         suppressed: 0 bytes in 0 blocks     
```

```
static int mq_notify_init(void)
{
        int ret;
        struct sigevent sev;

        sev.sigev_notify = SIGEV_THREAD;
        sev.sigev_notify_function = mq_handler;
        sev.sigev_notify_attributes = NULL;
        sev.sigev_value.sival_ptr = &mq;

        ret = mq_notify(mq, &sev);
        if (ret != 0)
                error("MQ notify register failed: %s", strerror(errno));

        return ret;
}
```
-- 
Thanks,
Parthiban N
https://www.linumiz.com
Berlin, Germany

             reply	other threads:[~2023-01-09 15:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09 15:13 Parthiban [this message]
2023-01-09 17:11 ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=abe21391-8d9f-4035-f0a5-d4f8a1a7d83f@linumiz.com \
    --to=parthiban@linumiz.com \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).