Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mmalloc] Avoid useless memset0
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 11 Jul 2014 10:04:34 +0000 (12:04 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 11 Jul 2014 10:04:34 +0000 (12:04 +0200)
src/xbt/mmalloc/mmalloc.c

index 72ca5a0..c91b4a0 100644 (file)
@@ -97,9 +97,12 @@ static void *register_morecore(struct mdesc *mdp, size_t size)
     /* Copy old info into new location */
     oldinfo = mdp->heapinfo;
     newinfo = (malloc_info *) align(mdp, newsize * sizeof(malloc_info));
-    memset(newinfo, 0, newsize * sizeof(malloc_info));
     memcpy(newinfo, oldinfo, mdp->heapsize * sizeof(malloc_info));
 
+    /* Initialise the new blockinfo : */
+    memset((char*) newinfo + mdp->heapsize * sizeof(malloc_info), 0,
+      (newsize - mdp->heapsize)* sizeof(malloc_info));
+
     /* Update the swag of busy blocks containing free fragments by applying the offset to all swag_hooks. Yeah. My hand is right in the fan and I still type */
     size_t offset=((char*)newinfo)-((char*)oldinfo);