From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id C23E93858C27 for ; Tue, 5 Apr 2022 13:13:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C23E93858C27 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from tarox.wildebeest.org (83-87-18-245.cable.dynamic.v4.ziggo.nl [83.87.18.245]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 1690B301BC17 for ; Tue, 5 Apr 2022 15:13:25 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 1496D413CD0E; Tue, 5 Apr 2022 15:13:25 +0200 (CEST) Message-ID: <189f86f680da2b0a0803bdd2871da96e1fde3775.camel@klomp.org> Subject: Re: [PATCHv2] libelf: Return already gotten Elf_Data from elf_getdata_rawchunk From: Mark Wielaard To: elfutils-devel@sourceware.org Date: Tue, 05 Apr 2022 15:13:24 +0200 In-Reply-To: <20220401141525.3384-1-mark@klomp.org> References: <20220401141525.3384-1-mark@klomp.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Evolution 3.28.5 (3.28.5-10.el7) Mime-Version: 1.0 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Apr 2022 13:13:29 -0000 Hi, On Fri, 2022-04-01 at 16:15 +0200, Mark Wielaard wrote: > elf_getdata_rawchunk keeps a list of Elf_Data_Chunk to track which > Elf_Data structures have already been requested. This allows elf_end > to clean up all internal data structures and the Elf_Data d_buf if > it was malloced. >=20 > But it didn't check if a chunk was already requested earlier. This > meant that if for example dwelf_elf_gnu_build_id was called multiple > times to lookup a build-id from the phdrs a new Elf_Data_Chunk was > created. This could slowly leak memory. >=20 > So also keep track of the offset from which the size and type of > the rawdata was requested so we can return existing data if it is > requested multiple times. >=20 > Note that the current cache is a simple linked list but the chain > is normally not that long. It is normally used to get chunks from > the phdrs, and there are normally less than 10. I pushed this. Cheers, Mark