diff src/stdlib/SDL_malloc.c @ 4077:a9df0628d256 SDL-1.2

Fixed bug #428 This fix is overkill, but approved by Doug Lea, and he'll be releasing a new version of his malloc.c sometime next month.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Jul 2007 00:07:02 +0000
parents d634945c6172
children a1b03ba2fcd0
line wrap: on
line diff
--- a/src/stdlib/SDL_malloc.c	Sun Jul 15 21:50:07 2007 +0000
+++ b/src/stdlib/SDL_malloc.c	Mon Jul 16 00:07:02 2007 +0000
@@ -3408,7 +3408,7 @@
     if (ss == 0) {  /* First time through or recovery */
       char* base = (char*)CALL_MORECORE(0);
       if (base != CMFAIL) {
-        asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);
+        asize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE);
         /* Adjust to end on a page boundary */
         if (!is_page_aligned(base))
           asize += (page_align((size_t)base) - (size_t)base);
@@ -3422,7 +3422,7 @@
     }
     else {
       /* Subtract out existing available top space from MORECORE request. */
-      asize = granularity_align(nb - m->topsize + TOP_FOOT_SIZE + SIZE_T_ONE);
+      asize = granularity_align(nb - m->topsize + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE);
       /* Use mem here only if it did continuously extend old space */
       if (asize < HALF_MAX_SIZE_T &&
           (br = (char*)(CALL_MORECORE(asize))) == ss->base+ss->size) {
@@ -3435,7 +3435,7 @@
       if (br != CMFAIL) {    /* Try to use/extend the space we did get */
         if (asize < HALF_MAX_SIZE_T &&
             asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) {
-          size_t esize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE - asize);
+          size_t esize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE - asize);
           if (esize < HALF_MAX_SIZE_T) {
             char* end = (char*)CALL_MORECORE(esize);
             if (end != CMFAIL)
@@ -3459,7 +3459,7 @@
   }
 
   if (HAVE_MMAP && tbase == CMFAIL) {  /* Try MMAP */
-    size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE;
+    size_t req = nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE;
     size_t rsize = granularity_align(req);
     if (rsize > nb) { /* Fail if wraps around zero */
       char* mp = (char*)(CALL_MMAP(rsize));
@@ -3472,7 +3472,7 @@
   }
 
   if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */
-    size_t asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);
+    size_t asize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE);
     if (asize < HALF_MAX_SIZE_T) {
       char* br = CMFAIL;
       char* end = CMFAIL;