From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2948 invoked by alias); 13 Feb 2020 21:01:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 2872 invoked by uid 89); 13 Feb 2020 21:01:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qk1-f196.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:references:from:autocrypt:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=3W/VqNR0LxJhSlsCCmSztLpnCvetR0porTbjwKVpARM=; b=JrEq2pg6KLIiGTc3ludStFZ82xOSRfX2r/SXRVMUKluW8WVXkHQG+7Km1BiX5RAGI5 MyKssZdo8gHOAQzm8cV0okH9BafUfRlgx4Vr9YL85cTOCDGmCEdpq91l9TYlg6sFer+Q uwew+miuqeZWyotEiJSwyDNdLNKnjP9SB0dW87sgeSxkiI/7CELURC+KcYD5BEDennk1 oxgwHIO32eDfTpQncMbM9EhbBnvDpVWJwf/EOmw4JF6WsiVOe7kfBZuxGeC3hSwuxKe9 9CpxASyCfPIYEnmcBY2MErOW4gRVPkVuPVQYCFM/fWZ0tQuK+coKJCQrJy2J91wjwt5a GJqQ== Return-Path: Subject: Re: [PATCH 3/5] resolv: Fix file handle leak in __resolv_conf_load [BZ #25429] To: libc-alpha@sourceware.org References: <4d8628bf1d8630c16de30d47732058ec82293429.1579631655.git.fweimer@redhat.com> From: Adhemerval Zanella Message-ID: Date: Thu, 13 Feb 2020 21:01:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <4d8628bf1d8630c16de30d47732058ec82293429.1579631655.git.fweimer@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2020-02/txt/msg00622.txt.bz2 On 21/01/2020 15:41, Florian Weimer wrote: > res_vinit_1 did not close the stream on errors, only on success. > This change moves closing the stream to __resolv_conf_load, for both > the success and error cases. > > Fixes commit 89f187a40fc0ad4e22838526bfe34d73f758b776 ("resolv: Use > getline for configuration file reading in res_vinit_1") and commit > 3f853f22c87f0b671c0366eb290919719fa56c0e ("resolv: Lift domain search > list limits [BZ #19569] [BZ #21475]"), where memory allocation was > introduced into res_vinit_1. > --- > resolv/res_init.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/resolv/res_init.c b/resolv/res_init.c > index 95dce098aa..09345718cd 100644 > --- a/resolv/res_init.c > +++ b/resolv/res_init.c > @@ -508,7 +508,6 @@ res_vinit_1 (FILE *fp, struct resolv_conf_parser *parser) > continue; > } > } > - fclose (fp); > } > if (__glibc_unlikely (nameserver_list_size (&parser->nameserver_list) == 0)) > { > @@ -593,6 +592,13 @@ __resolv_conf_load (struct __res_state *preinit) > } > resolv_conf_parser_free (&parser); > > + if (fp != NULL) > + { > + int saved_errno = errno; > + fclose (fp); > + __set_errno (saved_errno); > + } > + > return conf; > } Why not close the FILE on __resolv_conf_load? It make the FILE object cleanup as close as its creation, which usually improves readability.