]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blobdiff - src/core/mem.c
Fixed bug #28679: mem_realloc calculates mem_stats wrong and added test case for it
[pes-rpp/rpp-lwip.git] / src / core / mem.c
index 093f200da6aed890d102c1af0ef1e8d87af6b6d5..39ed926f4efe1e861d7e3d73e2efe46ade9ede3e 100644 (file)
@@ -414,8 +414,6 @@ mem_realloc(void *rmem, mem_size_t newsize)
   /* protect the heap from concurrent access */
   LWIP_MEM_FREE_PROTECT();
 
-  MEM_STATS_DEC_USED(used, (size - newsize));
-
   mem2 = (struct mem *)&ram[mem->next];
   if(mem2->used == 0) {
     /* The next struct is unused, we can simply move it at little */
@@ -441,6 +439,7 @@ mem_realloc(void *rmem, mem_size_t newsize)
     if (mem2->next != MEM_SIZE_ALIGNED) {
       ((struct mem *)&ram[mem2->next])->prev = ptr2;
     }
+    MEM_STATS_DEC_USED(used, (size - newsize));
     /* no need to plug holes, we've already done that */
   } else if (newsize + SIZEOF_STRUCT_MEM + MIN_SIZE_ALIGNED <= size) {
     /* Next struct is used but there's room for another struct mem with
@@ -462,6 +461,7 @@ mem_realloc(void *rmem, mem_size_t newsize)
     if (mem2->next != MEM_SIZE_ALIGNED) {
       ((struct mem *)&ram[mem2->next])->prev = ptr2;
     }
+    MEM_STATS_DEC_USED(used, (size - newsize));
     /* the original mem->next is used, so no need to plug holes! */
   }
   /* else {