summaryrefslogtreecommitdiff
path: root/nuttx/mm/mm_realloc.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-06-30 22:24:19 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-06-30 22:24:19 +0000
commitbfd3548a9c9f152407bd1b57d4bcaf5a534d7d77 (patch)
tree44ccdbba88b9fb0383fe5c2dba5279e8deac806c /nuttx/mm/mm_realloc.c
parent555eade3913955a67cc4b3a7bd62938426c3d985 (diff)
downloadpx4-nuttx-bfd3548a9c9f152407bd1b57d4bcaf5a534d7d77.tar.gz
px4-nuttx-bfd3548a9c9f152407bd1b57d4bcaf5a534d7d77.tar.bz2
px4-nuttx-bfd3548a9c9f152407bd1b57d4bcaf5a534d7d77.zip
Fixed several more realloc errors
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@296 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/mm/mm_realloc.c')
-rw-r--r--nuttx/mm/mm_realloc.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/nuttx/mm/mm_realloc.c b/nuttx/mm/mm_realloc.c
index e7d07d65b..d19e1c8dd 100644
--- a/nuttx/mm/mm_realloc.c
+++ b/nuttx/mm/mm_realloc.c
@@ -120,7 +120,16 @@ FAR void *realloc(FAR void *oldmem, size_t size)
oldsize = oldnode->size;
if (size <= oldsize)
{
- mm_shrinkchunk(oldnode, size);
+ /* Handle the special case where we are not going to change the
+ * size of the allocation.
+ */
+ if (size < oldsize)
+ {
+ mm_shrinkchunk(oldnode, size);
+ }
+
+ /* Then return the original address */
+
mm_givesemaphore();
return oldmem;
}
@@ -206,6 +215,7 @@ FAR void *realloc(FAR void *oldmem, size_t size)
/* Extend into the previous free chunk */
+ newmem = oldmem;
if (takeprev)
{
FAR struct mm_allocnode_s *newnode;
@@ -229,7 +239,7 @@ FAR void *realloc(FAR void *oldmem, size_t size)
if (takeprev < prevsize)
{
- /* No, just take what we need from the previous chunk
+ /* No.. just take what we need from the previous chunk
* and put it back into the free list
*/
@@ -248,14 +258,22 @@ FAR void *realloc(FAR void *oldmem, size_t size)
}
else
{
- /* Yes update its size (newnode->preceding is already set) */
+ /* Yes.. update its size (newnode->preceding is already set) */
- newnode->size += oldsize;
- next->preceding = newnode->size;
+ newnode->size += oldsize;
+ newnode->preceding |= MM_ALLOC_BIT;
+ next->preceding = newnode->size | (next->preceding & MM_ALLOC_BIT);
}
oldnode = newnode;
oldsize = newnode->size;
+
+ /* Now we have to move the user contents 'down' in memory. memcpy should
+ * should be save for this.
+ */
+
+ newmem = (FAR void*)((FAR char*)newnode + SIZEOF_MM_ALLOCNODE);
+ memcpy(newmem, oldmem, oldsize - SIZEOF_MM_ALLOCNODE);
}
/* Extend into the next free chunk */
@@ -309,12 +327,6 @@ FAR void *realloc(FAR void *oldmem, size_t size)
}
}
- /* Now we have to move the user contents 'down' in memory. memcpy should
- * should be save for this.
- */
-
- newmem = (FAR void*)((FAR char*)oldnode + SIZEOF_MM_ALLOCNODE);
- memcpy(newmem, oldmem, oldsize - SIZEOF_MM_ALLOCNODE);
mm_givesemaphore();
return newmem;
}