From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id BEDDB1F8C6 for ; Tue, 3 Aug 2021 15:09:55 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9CBA13954C16 for ; Tue, 3 Aug 2021 15:09:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9CBA13954C16 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628003394; bh=7y+yMfoWGh6Mvs2DTYAIDrZSMiE+wGwNwJbsJLXHFoA=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=i+MWKo9r96QCtRPxpCjt+SceHth+eLrPg7JNKJOxVtDtS717EK0zwWhs8RAqHQh1G Ct+1TC4Bgtnwz+LFRbS0jGKZhPFuj1/9QkHAmMb3d1gnJRE7IhRMFx5QnLEBrrnTSM ojr0Dgc8RpwAeMGLj+//dah9VMZfFmjJIfrT8x1o= Received: from anamika.lostca.se (anamika.lostca.se [IPv6:2a01:4f9:3b:505c::2]) by sourceware.org (Postfix) with ESMTPS id F137E386100C; Tue, 3 Aug 2021 15:09:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F137E386100C Received: from localhost (mail.lostca.se [65.21.75.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: spectre) by anamika.lostca.se (Postfix) with ESMTPSA id C8CFB1BA10; Tue, 3 Aug 2021 15:09:34 +0000 (UTC) Date: Tue, 3 Aug 2021 15:09:34 +0000 To: Siddhesh Poyarekar Subject: Re: [PATCH 2/5] gconv_parseconfdir: Fix memory leak Message-ID: <20210803150934.GB6986@lostca.se> References: <20210727174129.3612656-1-siddhesh@sourceware.org> <20210727174129.3612656-3-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210727174129.3612656-3-siddhesh@sourceware.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Arjun Shankar via Libc-alpha Reply-To: Arjun Shankar Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Hi Siddhesh, > The allocated `conf` would leak if we have to skip over the file due > to the underlying filesystem not supporting dt_type. > --- > iconv/gconv_parseconfdir.h | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/iconv/gconv_parseconfdir.h b/iconv/gconv_parseconfdir.h > index a4153e54c6..2f062689ec 100644 > --- a/iconv/gconv_parseconfdir.h > +++ b/iconv/gconv_parseconfdir.h > @@ -153,12 +153,11 @@ gconv_parseconfdir (const char *dir, size_t dir_len) > struct stat64 st; > if (asprintf (&conf, "%s/%s", buf, ent->d_name) < 0) > continue; > - if (ent->d_type == DT_UNKNOWN > - && (lstat64 (conf, &st) == -1 > - || !S_ISREG (st.st_mode))) > - continue; > > - found |= read_conf_file (conf, dir, dir_len); > + if (ent->d_type != DT_UNKNOWN > + || (lstat64 (conf, &st) != -1 && S_ISREG (st.st_mode))) > + found |= read_conf_file (conf, dir, dir_len); > + > free (conf); > } > } Reversed the condition to conditionally modify `found' first, then unconditionally free `conf' afterward to avoid a leak. The change looks correct to me. I'm wondering if the new condition is harder to read than simply !ing the old one. But I guess it's not that important compared to the fix itself. Reviewed-by: Arjun Shankar Cheers!