Message ID | 20231116011215.21144-1-chrisj@rtems.org |
---|---|
State | New |
Headers |
Return-Path: <newlib-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 07F753858C5F for <patchwork@sourceware.org>; Thu, 16 Nov 2023 01:12:44 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail.contemporary.net.au (msc1401703.lnk.telstra.net [139.130.245.200]) by sourceware.org (Postfix) with ESMTPS id 0400E3858D20 for <newlib@sourceware.org>; Thu, 16 Nov 2023 01:12:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0400E3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rtems.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=rtems.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0400E3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=139.130.245.200 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700097149; cv=none; b=Mv3toiLp6o2+neSIASA8PtxEcrsY55uWchj65iWvYU1CEzLLz2jbFm6+vyRNHaDTDjeOSdV67GRLSVTzaMdT68DQHiLaDdW3HYMP9/9wtXpF9xhYmjuyk3nrs47MjXgfQQOi0kjdz/q6szLcYQwVw1tt80948izn0zXidfrMPWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700097149; c=relaxed/simple; bh=0XE3umNxIKMrgbi5iWdqIvopIGS0a7iggWnJTjT+tLs=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=dxOxFOxVdw1y5tnBd9LseXbdA/6c6jTxOoQFip+Lx9DrZElydaH2BU5Mx6lUhxQ10eKueJZFo5GrnxVI9kgvL3OvIj1ZWpfj/PjMPvJkqQVokb/8ub/vKHBOTIIgeByYZC//GO8goPKpN9wi2cVq5bseDknUlbRbCVAaf6X9oow= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from ruru.contemporary.net.au (ruru.contemporary.net.au [10.10.5.2]) by mail.contemporary.net.au (8.15.2/8.15.2) with ESMTP id 3AG1CHnw090991; Thu, 16 Nov 2023 12:12:17 +1100 (EST) (envelope-from chrisj@rtems.org) From: chrisj@rtems.org To: newlib@sourceware.org Cc: Chris Johns <chrisj@rtems.org> Subject: [PATCH] Reclaim _REENT_MP_P5S in _reclaim_reent Date: Thu, 16 Nov 2023 12:12:15 +1100 Message-Id: <20231116011215.21144-1-chrisj@rtems.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> Errors-To: newlib-bounces+patchwork=sourceware.org@sourceware.org |
Series |
Reclaim _REENT_MP_P5S in _reclaim_reent
|
|
Commit Message
Chris Johns
Nov. 16, 2023, 1:12 a.m. UTC
From: Chris Johns <chrisj@rtems.org>
The change fixes a memory leak in threads that clean up using
_reclaim_reent.
RTEMS: Closes #4967
---
newlib/libc/reent/reent.c | 11 +++++++++++
1 file changed, 11 insertions(+)
Comments
On Nov 16 12:12, chrisj@rtems.org wrote: > From: Chris Johns <chrisj@rtems.org> > > The change fixes a memory leak in threads that clean up using > _reclaim_reent. > > RTEMS: Closes #4967 > --- > newlib/libc/reent/reent.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c > index db80ca06e..6bb271b9a 100644 > --- a/newlib/libc/reent/reent.c > +++ b/newlib/libc/reent/reent.c > @@ -59,6 +59,17 @@ _reclaim_reent (struct _reent *ptr) > } > if (_REENT_MP_RESULT(ptr)) > _free_r (ptr, _REENT_MP_RESULT(ptr)); > + if (_REENT_MP_P5S(ptr)) > + { > + struct _Bigint *thisone, *nextone; > + nextone = _REENT_MP_P5S(ptr); > + while (nextone) > + { > + thisone = nextone; > + nextone = nextone->_next; > + _free_r (ptr, thisone); > + } > + } The p5s data is allocated using Balloc, so the pointers are in freelist and should already be free'd at this point, starting at line 42. Please explain what happens and why free'ing the freelist is not sufficient in this case, preferredly as part of the commit message. Thanks, Corinna
On 16/11/2023 8:15 pm, Corinna Vinschen wrote: > On Nov 16 12:12, chrisj@rtems.org wrote: >> From: Chris Johns <chrisj@rtems.org> >> >> The change fixes a memory leak in threads that clean up using >> _reclaim_reent. >> >> RTEMS: Closes #4967 >> --- >> newlib/libc/reent/reent.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c >> index db80ca06e..6bb271b9a 100644 >> --- a/newlib/libc/reent/reent.c >> +++ b/newlib/libc/reent/reent.c >> @@ -59,6 +59,17 @@ _reclaim_reent (struct _reent *ptr) >> } >> if (_REENT_MP_RESULT(ptr)) >> _free_r (ptr, _REENT_MP_RESULT(ptr)); >> + if (_REENT_MP_P5S(ptr)) >> + { >> + struct _Bigint *thisone, *nextone; >> + nextone = _REENT_MP_P5S(ptr); >> + while (nextone) >> + { >> + thisone = nextone; >> + nextone = nextone->_next; >> + _free_r (ptr, thisone); >> + } >> + } > > The p5s data is allocated using Balloc, so the pointers are in freelist > and should already be free'd at this point, starting at line 42. Yes however P5S blocks allocated by Balloc via i2b are not passed to Bfree. > Please explain what happens and why free'ing the freelist is not > sufficient in this case, preferredly as part of the commit message. Yes good idea. How about: The _REENT_MP_P5S blocks are allocated using Balloc via i2b and linked in the pow5mult call. As a result these blocks are not on the freelist managed by the Bfree call. This change fixes a memory leak in threads that clean up using _reclaim_reent. Chris
On Nov 17 08:17, Chris Johns wrote: > On 16/11/2023 8:15 pm, Corinna Vinschen wrote: > > On Nov 16 12:12, chrisj@rtems.org wrote: > >> From: Chris Johns <chrisj@rtems.org> > >> > >> The change fixes a memory leak in threads that clean up using > >> _reclaim_reent. > >> > >> RTEMS: Closes #4967 > >> --- > >> newlib/libc/reent/reent.c | 11 +++++++++++ > >> 1 file changed, 11 insertions(+) > >> > >> diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c > >> index db80ca06e..6bb271b9a 100644 > >> --- a/newlib/libc/reent/reent.c > >> +++ b/newlib/libc/reent/reent.c > >> @@ -59,6 +59,17 @@ _reclaim_reent (struct _reent *ptr) > >> } > >> if (_REENT_MP_RESULT(ptr)) > >> _free_r (ptr, _REENT_MP_RESULT(ptr)); > >> + if (_REENT_MP_P5S(ptr)) > >> + { > >> + struct _Bigint *thisone, *nextone; > >> + nextone = _REENT_MP_P5S(ptr); > >> + while (nextone) > >> + { > >> + thisone = nextone; > >> + nextone = nextone->_next; > >> + _free_r (ptr, thisone); > >> + } > >> + } > > > > The p5s data is allocated using Balloc, so the pointers are in freelist > > and should already be free'd at this point, starting at line 42. > > Yes however P5S blocks allocated by Balloc via i2b are not passed to Bfree. Aaah, right, it really never does. > > Please explain what happens and why free'ing the freelist is not > > sufficient in this case, preferredly as part of the commit message. > > Yes good idea. How about: > > The _REENT_MP_P5S blocks are allocated using Balloc via i2b and linked in the > pow5mult call. As a result these blocks are not on the freelist managed by the > Bfree call. This change fixes a memory leak in threads that clean up using > _reclaim_reent. Yeah, sounds good. Please resend with this commit message. Thanks, Corinna
diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c index db80ca06e..6bb271b9a 100644 --- a/newlib/libc/reent/reent.c +++ b/newlib/libc/reent/reent.c @@ -59,6 +59,17 @@ _reclaim_reent (struct _reent *ptr) } if (_REENT_MP_RESULT(ptr)) _free_r (ptr, _REENT_MP_RESULT(ptr)); + if (_REENT_MP_P5S(ptr)) + { + struct _Bigint *thisone, *nextone; + nextone = _REENT_MP_P5S(ptr); + while (nextone) + { + thisone = nextone; + nextone = nextone->_next; + _free_r (ptr, thisone); + } + } #ifdef _REENT_SMALL } #endif