From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27676 invoked by alias); 23 Jan 2012 16:18:11 -0000 Received: (qmail 27664 invoked by uid 22791); 23 Jan 2012 16:18:10 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Jan 2012 16:17:57 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0NGHvi5021080 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Jan 2012 11:17:57 -0500 Received: from host2.jankratochvil.net (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q0NGHqO7000563 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 23 Jan 2012 11:17:54 -0500 Date: Mon, 23 Jan 2012 16:25:00 -0000 From: Jan Kratochvil To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [patch] find_and_open_script: Fix failed fdopen Message-ID: <20120123161751.GA25494@host2.jankratochvil.net> References: <20120123160309.GA25174@host2.jankratochvil.net> <4F1D862D.1060608@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4F1D862D.1060608@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-01/txt/msg00776.txt.bz2 On Mon, 23 Jan 2012 17:09:17 +0100, Pedro Alves wrote: > On 01/23/2012 04:03 PM, Jan Kratochvil wrote: > > @@ -513,6 +513,17 @@ find_and_open_script (const char *script_file, int search_path, > > do_cleanups (old_cleanups); > > > > *streamp = fdopen (fd, FOPEN_RT); > > + if (*streamp == NULL) > > + { > > + int save_errno = errno; > > + > > + if (full_pathp) > > + xfree (*full_pathp); > > + do_cleanups (old_cleanups); > > This do_cleanups doesn't look right. From the patch context, there's > already do_cleanups(old_cleanups) call a bit above. Oops, thanks. Also missing close there. Regards, Jan gdb/ 2012-01-23 Jan Kratochvil * cli/cli-cmds.c (find_and_open_script): Handle failure of fdopen. --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -513,6 +513,17 @@ find_and_open_script (const char *script_file, int search_path, do_cleanups (old_cleanups); *streamp = fdopen (fd, FOPEN_RT); + if (*streamp == NULL) + { + int save_errno = errno; + + close (fd); + if (full_pathp) + xfree (*full_pathp); + errno = save_errno; + return 0; + } + return 1; }