public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Manuel Wienand <Manuel.Wienand@ubitronix.com>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: RE: 1.7.9: mq_unlink/mq_open leaks handles
Date: Mon, 04 Apr 2011 20:26:00 -0000	[thread overview]
Message-ID: <0C11C5BF0B29FD43A8D0250F711D497F89DC3AE22D@ex01-ubitronix.ubitronix.local> (raw)

Grmpf,

sorry for the spam. Just realized that mq_close is still needed, even if we don't want to open the queue again.
mq_unlink just deletes the file while mq_close frees the resources of the mqd_t struct.

Manuel


> -----Original Message-----
> Sent: Monday, April 04, 2011 2:50 PM
> Subject: 1.7.9: mq_unlink/mq_open leaks handles
> 
> Hallo,
> 
> it seems that mq_unlink and/or mq_open forget to close some handles (5
> to be precise).
> How to test:
> Execute the following code and watch the number of handles in the
> windows task-manager (processes tab, you can add a column there). For
> me it increases by 5 with every loop.
> 
> Tested with this DLL: cygwin1-20110327.dll
> 
> Thanks,
> 
> Manuel
> 
> 
> 
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <mqueue.h>
> #include <string.h>
> #include <errno.h>
> #include <fcntl.h>
> #include <unistd.h>
> 
> int main(void)
> {
>   int res;
>   int i = 0;
>   char msgQueueTestName[] = "./testQueue";
>   mqd_t testQueue;
>   struct mq_attr  attrQueue;
>   memset(&attrQueue,0x00,sizeof(attrQueue));
>   attrQueue.mq_maxmsg  = 10;  /* room for X messages in the queue */
>   attrQueue.mq_msgsize = 20;  /* maximum size of a message */
> 
>   while(1)
>   {
>     sleep(1);
>     i++;
>     printf("Loop #%d\n", i); fflush(stdout);
> 
>     // Remove old queues before trying to create a new one.
>     res = mq_unlink(msgQueueTestName);
>     if ((res == -1) && (errno != ENOENT))
>     {
>       // Don't print anything if the queue can't be unlinked, because
> it doesn't exist.
>      printf("Failed to unlink msg queue %s: %s %d\n", msgQueueTestName,
> sys_errlist[errno],errno);
>     }
> 
>     testQueue = mq_open(msgQueueTestName, O_RDWR | O_CREAT | O_EXCL,
> S_IRWXU | S_IRWXG, &attrQueue);
>     if( testQueue == (mqd_t)-1 )
>     {
>       printf("Failed to open msg queue %s: %s %d\n", msgQueueTestName,
> sys_errlist[errno],errno);
>     }
> 
>     res = mq_unlink(msgQueueTestName);
>     if (res == -1)
>     {
>       printf("Failed to unlink msg queue %s: %s %d\n",
> msgQueueTestName, sys_errlist[errno],errno);
>     }
>   }
> 
> 	return EXIT_SUCCESS;
> }

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

             reply	other threads:[~2011-04-04 13:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-04 20:26 Manuel Wienand [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-04-04 13:06 Manuel Wienand

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=0C11C5BF0B29FD43A8D0250F711D497F89DC3AE22D@ex01-ubitronix.ubitronix.local \
    --to=manuel.wienand@ubitronix.com \
    --cc=cygwin@cygwin.com \
    /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).