From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 12B103858C66 for ; Fri, 17 Nov 2023 12:08:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12B103858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12B103858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700222907; cv=none; b=qxkqh8os6sPGA3YRrKvTpHxfYsgTRXooB1l3O+KJUhnrm/Z34vXHw0y1gRpFICErLqzBg+EVvH1AIyjUsoeD8PMShakil4lFvGLJ88DTz9mieftv/IlPTpNjujF0tFQk954HFVi6qV313no0g0fBs/DEt429HiJx04pNjKobGTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700222907; c=relaxed/simple; bh=1gKekpRJ3lmZJ4VYCtabcfa+poFKx2jHrfesXggTh+s=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=t6dCDvUf82YhGsRvQbHrIout8lkHhKRprgD69+3YTwrbInQaJMrG/oakbUhjMbij3wGznW0XIzI8FLC1P5aJ6KQk5fodjKqCssXwb6QerPgLnSa3MT/rp3nUs+3AcT5jRyTGftEFsG/ACLNU5Rj5RdOMKjPo75Y2UmsX6tLaKp8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700222905; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=Vlak8RJy7KrU/UyrGwNtaX/ngU4v+ERmLfG7z9fj1GA=; b=LLqxxjE4G3Jcdzk00BSzPpLx+QgQzDE5V5eQI5GIqA2oFNsSLSpJe4yg9PCbZQICf+Apf6 4xs7naTpDF3FZgrKa1enXAEZO7vZVLxxLzlLqaHk4GL3vmeHVd5tTgPlwJk79GCytavDq7 A45WqCzBDMTq3nFDuDTL+btRUV5GGPk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-580-uKNyxI9QPEKA_z5UgoOS6Q-1; Fri, 17 Nov 2023 07:08:24 -0500 X-MC-Unique: uKNyxI9QPEKA_z5UgoOS6Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D0EF1C06358 for ; Fri, 17 Nov 2023 12:08:24 +0000 (UTC) Received: from calimero.vinschen.de (unknown [10.39.193.251]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEDDB2166B27 for ; Fri, 17 Nov 2023 12:08:23 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id E24F2A80BE0; Fri, 17 Nov 2023 13:08:22 +0100 (CET) Date: Fri, 17 Nov 2023 13:08:22 +0100 From: Corinna Vinschen To: newlib@sourceware.org Subject: Re: [PATCH] Reclaim _REENT_MP_P5S in _reclaim_reent Message-ID: Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org References: <20231116011215.21144-1-chrisj@rtems.org> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 List-Id: 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 > >> > >> 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