[RTEMS Project] #3755: leak in realloc
RTEMS trac
trac at rtems.org
Wed Jun 5 16:23:46 UTC 2019
#3755: leak in realloc
---------------------------+--------------------------
Reporter: Jeffrey Hill | Owner: (none)
Type: defect | Status: new
Priority: normal | Milestone:
Component: admin | Version: 4.11
Severity: normal | Keywords: realloc leak
Blocked By: | Blocking:
---------------------------+--------------------------
We are running Lua in an RTEMS system which, by default, uses realloc for
memory allocation. We observe a memory leak on RTEMS unless we replace the
default Lua allocator on RTEMS as follows. The net result being avoidance
of any calls to realloc, and instead fall back to Lua memory allocation
based solely on malloc and free.
nios2-rtems4.11-gcc (GCC) 4.9.3 20150626 (RTEMS 4.11, RSB no-repo, Newlib
2.2.0.20150423)
configure --target=nios2-rtems4.11 --prefix=/ade/rtems/install/rtems-4-11
--disable-itron --disable-tests --enable-posix --enable-cxx --enable-
rtemsbsp=altera-sys-config-S43X-TDAQ-dev --enable-networking
This is occurring in 4.11.1.99. We definitely need to sync up, however our
cursory search in the bug database indicated that this might need to be
reported.
{{{
#if defined ( CAS_LUA_DONT_USE_REALLOC )
#pragma message("installing RTEMS workaround for realloc bugs")
void * RspThr :: LuaHandle :: m_alloc ( void * const pPriv, void * const
pOld,
const size_t osize, const size_t nsize
)
{
void * pNew;
if ( nsize > 0u ) {
if ( pOld ) {
if ( osize == nsize ) {
pNew = pOld;
}
else {
pNew = malloc ( nsize );
if ( pNew ) {
memcpy ( pNew, pOld, std :: min ( osize, nsize ) );
free ( pOld );
}
}
}
else {
pNew = malloc ( nsize );
}
}
else {
free ( pOld );
pNew = NULL;
}
return pNew;
}
#else
void * RspThr :: LuaHandle :: m_alloc ( void * const pPriv, void * const
pOld,
const size_t osize, const size_t nsize )
{
if ( nsize == 0 ) {
free ( pOld );
return NULL;
}
else {
void * const pNew = realloc ( pOld, nsize );
return pNew;
}
}
#endif /* ifdef CAS_LUA_DONT_USE_REALLOC */
}}}
--
Ticket URL: <http://devel.rtems.org/ticket/3755>
RTEMS Project <http://www.rtems.org/>
RTEMS Project
More information about the bugs
mailing list