From: Keir Fraser Date: Wed, 2 Apr 2008 14:32:13 +0000 (+0100) Subject: minios: Fix xfree() bug. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6e756bd86c4d0dd8ccc2c93b748ea35de121dea5;p=people%2Fliuw%2Flibxenctrl-split%2Fmini-os.git minios: Fix xfree() bug. It has to check first if the memory to free is so big as to be freed directly by free_pages. mini-os domains crash without this patch if vfb is misconfigured. Signed-off-by: INAKOSHI Hiroya --- diff --git a/lib/xmalloc.c b/lib/xmalloc.c index d4c3941..82d5cc6 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -208,6 +208,13 @@ void xfree(const void *p) pad = (struct xmalloc_pad *)p - 1; hdr = (struct xmalloc_hdr *)((char *)p - pad->hdr_size); + /* Big allocs free directly. */ + if ( hdr->size >= PAGE_SIZE ) + { + free_pages(hdr, get_order(hdr->size)); + return; + } + /* We know hdr will be on same page. */ if(((long)p & PAGE_MASK) != ((long)hdr & PAGE_MASK)) { @@ -222,13 +229,6 @@ void xfree(const void *p) *(int*)0=0; } - /* Big allocs free directly. */ - if ( hdr->size >= PAGE_SIZE ) - { - free_pages(hdr, get_order(hdr->size)); - return; - } - /* Merge with other free block, or put in list. */ /* spin_lock_irqsave(&freelist_lock, flags); */ list_for_each_entry_safe( i, tmp, &freelist, freelist )