From 6fb265fa3b4fb9ebbafad34586d9087c28b6186f Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 19 Sep 2006 17:30:04 +0000 Subject: [PATCH] Reorder mm bounds_check code to reduce window for a dmeventd race. (dm_free_aux) --- libdm/mm/dbg_malloc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libdm/mm/dbg_malloc.c b/libdm/mm/dbg_malloc.c index 48fd43dc6..8986b21e2 100644 --- a/libdm/mm/dbg_malloc.c +++ b/libdm/mm/dbg_malloc.c @@ -135,12 +135,6 @@ void dm_free_aux(void *p) /* have we freed this before ? */ assert(mb->id != 0); - mb->id = 0; - - /* stomp a different pattern across the memory */ - ptr = ((char *) mb) + sizeof(struct memblock); - for (i = 0; i < mb->length; i++) - *ptr++ = i & 1 ? (char) 0xde : (char) 0xad; /* unlink */ if (mb->prev) @@ -153,6 +147,13 @@ void dm_free_aux(void *p) else _tail = mb->prev; + mb->id = 0; + + /* stomp a different pattern across the memory */ + ptr = ((char *) mb) + sizeof(struct memblock); + for (i = 0; i < mb->length; i++) + *ptr++ = i & 1 ? (char) 0xde : (char) 0xad; + assert(_mem_stats.blocks_allocated); _mem_stats.blocks_allocated--; _mem_stats.bytes -= mb->length;