fixed a bug in xma.c
This commit is contained in:
parent
afe798f146
commit
7e318991fe
@ -91,7 +91,7 @@ struct moo_xma_t
|
|||||||
|
|
||||||
moo_uint8_t* start; /* zone beginning */
|
moo_uint8_t* start; /* zone beginning */
|
||||||
moo_uint8_t* end; /* zone end */
|
moo_uint8_t* end; /* zone end */
|
||||||
int external;
|
int internal;
|
||||||
|
|
||||||
/** pointer array to free memory blocks */
|
/** pointer array to free memory blocks */
|
||||||
moo_xma_fblk_t* xfree[MOO_XMA_FIXED + MOO_XMA_SIZE_BITS + 1];
|
moo_xma_fblk_t* xfree[MOO_XMA_FIXED + MOO_XMA_SIZE_BITS + 1];
|
||||||
|
@ -173,6 +173,7 @@ int moo_xma_init (moo_xma_t* xma, moo_mmgr_t* mmgr, void* zoneptr, moo_oow_t zon
|
|||||||
{
|
{
|
||||||
moo_xma_fblk_t* free;
|
moo_xma_fblk_t* free;
|
||||||
moo_oow_t xfi;
|
moo_oow_t xfi;
|
||||||
|
int internal = 0;
|
||||||
|
|
||||||
if (!zoneptr)
|
if (!zoneptr)
|
||||||
{
|
{
|
||||||
@ -184,10 +185,8 @@ int moo_xma_init (moo_xma_t* xma, moo_mmgr_t* mmgr, void* zoneptr, moo_oow_t zon
|
|||||||
|
|
||||||
zoneptr = MOO_MMGR_ALLOC(mmgr, zonesize);
|
zoneptr = MOO_MMGR_ALLOC(mmgr, zonesize);
|
||||||
if (MOO_UNLIKELY(!zoneptr)) return -1;
|
if (MOO_UNLIKELY(!zoneptr)) return -1;
|
||||||
}
|
|
||||||
else
|
internal = 1;
|
||||||
{
|
|
||||||
xma->external = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free = (moo_xma_fblk_t*)zoneptr;
|
free = (moo_xma_fblk_t*)zoneptr;
|
||||||
@ -212,6 +211,7 @@ int moo_xma_init (moo_xma_t* xma, moo_mmgr_t* mmgr, void* zoneptr, moo_oow_t zon
|
|||||||
/* let it be the head, which is natural with only a block */
|
/* let it be the head, which is natural with only a block */
|
||||||
xma->start = (moo_uint8_t*)free;
|
xma->start = (moo_uint8_t*)free;
|
||||||
xma->end = xma->start + zonesize;
|
xma->end = xma->start + zonesize;
|
||||||
|
xma->internal = 1;
|
||||||
|
|
||||||
/* initialize some statistical variables */
|
/* initialize some statistical variables */
|
||||||
#if defined(MOO_XMA_ENABLE_STAT)
|
#if defined(MOO_XMA_ENABLE_STAT)
|
||||||
@ -229,7 +229,7 @@ void moo_xma_fini (moo_xma_t* xma)
|
|||||||
{
|
{
|
||||||
/* the head must point to the free chunk allocated in init().
|
/* the head must point to the free chunk allocated in init().
|
||||||
* let's deallocate it */
|
* let's deallocate it */
|
||||||
if (!xma->external) MOO_MMGR_FREE (xma->_mmgr, xma->start);
|
if (xma->internal) MOO_MMGR_FREE (xma->_mmgr, xma->start);
|
||||||
xma->start = MOO_NULL;
|
xma->start = MOO_NULL;
|
||||||
xma->end = MOO_NULL;
|
xma->end = MOO_NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user