From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id BEC323858D34 for ; Sat, 3 Jul 2021 22:03:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BEC323858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [192.168.1.145] (ip197.226-51-69.sogetel.net [69.51.226.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id E49C61E01F; Sat, 3 Jul 2021 18:03:17 -0400 (EDT) Subject: Re: [PATCH] selftest-arch: free arches array To: =?UTF-8?Q?Alexandra_H=c3=a1jkov=c3=a1?= , gdb-patches@sourceware.org References: <20210702105613.2580637-1-ahajkova@redhat.com> From: Simon Marchi Message-ID: <16ab7dce-bf2c-17da-ed34-034ea8310b08@simark.ca> Date: Sat, 3 Jul 2021 18:03:17 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210702105613.2580637-1-ahajkova@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Jul 2021 22:03:20 -0000 On 2021-07-02 6:56 a.m., Alexandra Hájková via Gdb-patches wrote: > From: Alexandra Hájková > > Found by coverity scanning. > > gdb/ChangeLog: > > 2021-07-02 Alexandra Hájková > > * selftest-arch.c (struct gdbarch_selftest): free arches array > --- > gdb/selftest-arch.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c > index 0eef134d484..03b07108a2e 100644 > --- a/gdb/selftest-arch.c > +++ b/gdb/selftest-arch.c > @@ -79,7 +79,9 @@ struct gdbarch_selftest : public selftest > } > > reset (); > + free((char *)arches[i]); I don't think the elements of the array need to be freed, as here in gdbarch_printable_names, we just push the pointer handed by BFD, we don't duplicate the strings: https://gitlab.com/gnutools/gdb/-/blob/3bdd3c041881470878cf47250a825a94d381fa64/gdb/gdbarch.c#L5580 > } > + free(arches); For this, I would suggest modernizing gdbarch_printable_names by making it return an std::vector instead. It will simplify that code (gdbarch_printable_names) as well as the callers, making memory management automatic. Simon