From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E2891385802E; Thu, 4 Aug 2022 15:13:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2891385802E From: "mark at klomp dot org" To: elfutils-devel@sourceware.org Subject: [Bug libdw/29434] Memory leak in `dwarf_getscopes` Date: Thu, 04 Aug 2022 15:13:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: elfutils X-Bugzilla-Component: libdw X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mark at klomp dot org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: mark at klomp dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 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: Thu, 04 Aug 2022 15:13:19 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29434 --- Comment #3 from Mark Wielaard --- (In reply to Pablo Galindo Salgado from comment #2) > > it could in theory also be zero >=20 > In this case, the result was 0 (I am working with Matt) Interesting, I assumed it was on a failure path. My proposed patch would have been: diff --git a/libdw/dwarf_getscopes.c b/libdw/dwarf_getscopes.c index 5662eecf..676d62f3 100644 --- a/libdw/dwarf_getscopes.c +++ b/libdw/dwarf_getscopes.c @@ -100,7 +100,7 @@ origin_match (unsigned int depth, struct Dwarf_Die_Chain *die, void *arg) Dwarf_Die *scopes =3D realloc (a->scopes, nscopes * sizeof scopes[0]); if (scopes =3D=3D NULL) { - free (a->scopes); + /* a->scopes will be freed by dwarf_getscopes on error. */ __libdw_seterrno (DWARF_E_NOMEM); return -1; } @@ -198,6 +198,8 @@ dwarf_getscopes (Dwarf_Die *cudie, Dwarf_Addr pc, Dwarf= _Die **scopes) if (result > 0) *scopes =3D a.scopes; + else if (result < 0) + free (a.scopes); return result; } But if the result is zero I don't believe I fully understand yet how the le= ak happens. --=20 You are receiving this mail because: You are on the CC list for the bug.=