Explorar el Código

fix undefined behavior in free

Alexander Monakov hace 7 años
padre
commit
60ab365cae
Se han modificado 1 ficheros con 3 adiciones y 2 borrados
  1. 3 2
      src/malloc/malloc.c

+ 3 - 2
src/malloc/malloc.c

@@ -450,14 +450,15 @@ copy_realloc:
 
 void free(void *p)
 {
-	struct chunk *self = MEM_TO_CHUNK(p);
-	struct chunk *next;
+	struct chunk *self, *next;
 	size_t final_size, new_size, size;
 	int reclaim=0;
 	int i;
 
 	if (!p) return;
 
+	self = MEM_TO_CHUNK(p);
+
 	if (IS_MMAPPED(self)) {
 		size_t extra = self->psize;
 		char *base = (char *)self - extra;