From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 05C23398B8B7; Fri, 21 May 2021 13:34:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05C23398B8B7 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: POSIX msg queues: destroy msg queue fhandler in case of error X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 723f38b10af6d465ccdd41af408e8c3d84331033 X-Git-Newrev: bce3563e988137a23a6867d749b727825a2ad96a Message-Id: <20210521133438.05C23398B8B7@sourceware.org> Date: Fri, 21 May 2021 13:34:38 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 May 2021 13:34:38 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bce3563e988137a23a6867d749b727825a2ad96a commit bce3563e988137a23a6867d749b727825a2ad96a Author: Corinna Vinschen Date: Fri May 21 15:26:51 2021 +0200 Cygwin: POSIX msg queues: destroy msg queue fhandler in case of error ...and don't leave a descriptor dangling Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/posix_ipc.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/posix_ipc.cc b/winsup/cygwin/posix_ipc.cc index fc483bdc8..8101a28f9 100644 --- a/winsup/cygwin/posix_ipc.cc +++ b/winsup/cygwin/posix_ipc.cc @@ -392,7 +392,6 @@ mq_open (const char *name, int oflag, ...) fh = (fhandler_mqueue *) build_fh_dev (*mqueue_dev, name); if (!fh) __leave; - fdm = fh; mqinfo = fh->mqinfo_create ((HANDLE) _get_osfhandle (fd), filesize, mode, nonblock); @@ -426,6 +425,7 @@ mq_open (const char *name, int oflag, ...) if (fchmod (fd, mode) == -1) __leave; close (fd); + fdm = fh; return (mqd_t) fdm; } @@ -468,7 +468,6 @@ mq_open (const char *name, int oflag, ...) fh = (fhandler_mqueue *) build_fh_dev (*mqueue_dev, name); if (!fh) __leave; - fdm = fh; mqinfo = fh->mqinfo_open ((HANDLE) _get_osfhandle (fd), statbuff.st_size, statbuff.st_mode, nonblock); @@ -476,6 +475,7 @@ mq_open (const char *name, int oflag, ...) __leave; close (fd); + fdm = fh; return (mqd_t) fdm; } __except (EFAULT) {} @@ -486,6 +486,11 @@ mq_open (const char *name, int oflag, ...) unlink (mqname); if (fd >= 0) close (fd); + if (fh) + { + fh->close (); + delete fh; + } return (mqd_t) -1; }