delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/04/04/09:06:37

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=0.0 required=5.0 tests=AWL,BAYES_00,TW_MQ,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
From: Manuel Wienand <Manuel DOT Wienand AT ubitronix DOT com>
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Date: Mon, 4 Apr 2011 15:06:35 +0200
Subject: RE: 1.7.9: mq_unlink/mq_open leaks handles
Message-ID: <0C11C5BF0B29FD43A8D0250F711D497F89DC3AE22D@ex01-ubitronix.ubitronix.local>
x-esetresult: clean, is OK
x-esetid: 457DA920DB39A03D163D
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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 m=
qd_t struct.

Manuel


> -----Original Message-----
> Sent: Monday, April 04, 2011 2:50 PM
> Subject: 1.7.9: mq_unlink/mq_open leaks handles
>=20
> Hallo,
>=20
> 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.
>=20
> Tested with this DLL: cygwin1-20110327.dll
>=20
> Thanks,
>=20
> Manuel
>=20
>=20
>=20
>=20
> #include <stdio.h>
> #include <stdlib.h>
> #include <mqueue.h>
> #include <string.h>
> #include <errno.h>
> #include <fcntl.h>
> #include <unistd.h>
>=20
> int main(void)
> {
>   int res;
>   int i =3D 0;
>   char msgQueueTestName[] =3D "./testQueue";
>   mqd_t testQueue;
>   struct mq_attr  attrQueue;
>   memset(&attrQueue,0x00,sizeof(attrQueue));
>   attrQueue.mq_maxmsg  =3D 10;  /* room for X messages in the queue */
>   attrQueue.mq_msgsize =3D 20;  /* maximum size of a message */
>=20
>   while(1)
>   {
>     sleep(1);
>     i++;
>     printf("Loop #%d\n", i); fflush(stdout);
>=20
>     // Remove old queues before trying to create a new one.
>     res =3D mq_unlink(msgQueueTestName);
>     if ((res =3D=3D -1) && (errno !=3D 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);
>     }
>=20
>     testQueue =3D mq_open(msgQueueTestName, O_RDWR | O_CREAT | O_EXCL,
> S_IRWXU | S_IRWXG, &attrQueue);
>     if( testQueue =3D=3D (mqd_t)-1 )
>     {
>       printf("Failed to open msg queue %s: %s %d\n", msgQueueTestName,
> sys_errlist[errno],errno);
>     }
>=20
>     res =3D mq_unlink(msgQueueTestName);
>     if (res =3D=3D -1)
>     {
>       printf("Failed to unlink msg queue %s: %s %d\n",
> msgQueueTestName, sys_errlist[errno],errno);
>     }
>   }
>=20
> 	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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019