Merge pull request #6 from kareem-wolfssl/realloc

Update example pvPortRealloc example.
master
David Garske 2023-07-20 09:48:55 -07:00 committed by GitHub
commit 37c7afab75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 24 deletions

View File

@ -310,21 +310,20 @@ BlockLink_t *pxLink;
void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn = NULL;
void *pvReturn = NULL;
if(pv)
if (xWantedSize == 0)
{
BlockLink_t *pxLink = (BlockLink_t *)((char*)pv - xHeapStructSize);
if(pxLink->xBlockSize & xBlockAllocatedBit)
if (pv)
vPortFree(pv);
}
else if (pv)
{
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
uint32_t blockSize = (pxLink->xBlockSize & ~xBlockAllocatedBit);
blockSize -= xHeapStructSize;
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
memcpy(pvReturn, pv, blockSize);
vPortFree(pv);
}
memcpy(pvReturn, pv, xWantedSize);
vPortFree(pv);
}
}
else {

View File

@ -319,21 +319,20 @@ BlockLink_t *pxLink;
void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn = NULL;
void *pvReturn = NULL;
if(pv)
if (xWantedSize == 0)
{
BlockLink_t *pxLink = (BlockLink_t *)((char*)pv - uxHeapStructSize);
if(pxLink->xBlockSize & xBlockAllocatedBit)
if (pv)
vPortFree(pv);
}
else if (pv)
{
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
uint32_t blockSize = (pxLink->xBlockSize & ~xBlockAllocatedBit);
blockSize -= uxHeapStructSize;
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
memcpy(pvReturn, pv, blockSize);
vPortFree(pv);
}
memcpy(pvReturn, pv, xWantedSize);
vPortFree(pv);
}
}
else {