From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cc-smtpout2.netcologne.de (cc-smtpout2.netcologne.de [89.1.8.212]) by sourceware.org (Postfix) with ESMTPS id EEDEE3851C12; Thu, 28 May 2020 18:55:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EEDEE3851C12 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 800E612C78; Thu, 28 May 2020 20:55:48 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 7CD3C11EED; Thu, 28 May 2020 20:55:48 +0200 (CEST) Received: from [2001:4dd7:7821:0:f672:738:36da:e63a] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.11.6) (envelope-from ) id 5ed00934-4f6f-7f0000012729-7f000001c89e-1 for ; Thu, 28 May 2020 20:55:48 +0200 Received: from linux-p51k.fritz.box (2001-4dd7-7821-0-f672-738-36da-e63a.ipv6dyn.netcologne.de [IPv6:2001:4dd7:7821:0:f672:738:36da:e63a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Thu, 28 May 2020 20:55:46 +0200 (CEST) Subject: Re: [PATCH, committed] [9/10/11 Regression] PR fortran/95104 - Segfault on a legal WAIT statement To: Harald Anlauf Cc: gcc-patches , fortran References: From: Thomas Koenig Message-ID: <769b485a-58e6-9d0c-5b1c-54bbcb3f8ec5@netcologne.de> Date: Thu, 28 May 2020 20:55:45 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 May 2020 18:55:51 -0000 Hi Harald, > There are two possible fixes for this: > > (1) guard the call to unlock_unit by: > > diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c > index cd51679ff46..296be0711a2 100644 > --- a/libgfortran/io/transfer.c > +++ b/libgfortran/io/transfer.c > @@ -4508,7 +4508,8 @@ st_wait_async (st_parameter_wait *wtp) > async_wait (&(wtp->common), u->au); > } > > - unlock_unit (u); > + if (u) > + unlock_unit (u); > } > > > > (2) in unlock_unit(): > > diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c > index 0030d7e8701..a3b0656cb90 100644 > --- a/libgfortran/io/unit.c > +++ b/libgfortran/io/unit.c > @@ -767,9 +767,12 @@ close_unit_1 (gfc_unit *u, int locked) > void > unlock_unit (gfc_unit *u) > { > - NOTE ("unlock_unit = %d", u->unit_number); > - UNLOCK (&u->lock); > - NOTE ("unlock_unit done"); > + if (u) > + { > + NOTE ("unlock_unit = %d", u->unit_number); > + UNLOCK (&u->lock); > + NOTE ("unlock_unit done"); > + } > } > > /* close_unit()-- Close a unit. The stream is closed, and any memory > > > Does anybody prefer one over the other, or just commit both (which might be > preferable to catch other unguarded cases)? I think the second one is more robust - like you say, this may catch other cases. If we have that one, we don't need the first one. Regards Thomas