[v2] Reclaim _REENT_MP_P5S in _reclaim_reent

Message ID 20231120010458.32916-1-chrisj@rtems.org
State New
Headers
Series [v2] Reclaim _REENT_MP_P5S in _reclaim_reent |

Commit Message

Chris Johns Nov. 20, 2023, 1:04 a.m. UTC
  From: Chris Johns <chrisj@rtems.org>

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.

RTEMS: Closes #4967
---
 newlib/libc/reent/reent.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
  

Comments

Corinna Vinschen Nov. 20, 2023, 10:23 a.m. UTC | #1
On Nov 20 12:04, chrisj@rtems.org wrote:
> From: Chris Johns <chrisj@rtems.org>
> 
> 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.
> 
> RTEMS: Closes #4967
> ---
>  newlib/libc/reent/reent.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)

Pushed.

Thanks,
Corinna
  

Patch

diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c
index db80ca06e..74503fa59 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