Fixed bug #428 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Mon, 16 Jul 2007 00:07:02 +0000
branchSDL-1.2
changeset 4077a9df0628d256
parent 4076 9a7c62bbc8b3
child 4078 5e6f2972f963
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.
src/stdlib/SDL_malloc.c
     1.1 --- a/src/stdlib/SDL_malloc.c	Sun Jul 15 21:50:07 2007 +0000
     1.2 +++ b/src/stdlib/SDL_malloc.c	Mon Jul 16 00:07:02 2007 +0000
     1.3 @@ -3408,7 +3408,7 @@
     1.4      if (ss == 0) {  /* First time through or recovery */
     1.5        char* base = (char*)CALL_MORECORE(0);
     1.6        if (base != CMFAIL) {
     1.7 -        asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);
     1.8 +        asize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE);
     1.9          /* Adjust to end on a page boundary */
    1.10          if (!is_page_aligned(base))
    1.11            asize += (page_align((size_t)base) - (size_t)base);
    1.12 @@ -3422,7 +3422,7 @@
    1.13      }
    1.14      else {
    1.15        /* Subtract out existing available top space from MORECORE request. */
    1.16 -      asize = granularity_align(nb - m->topsize + TOP_FOOT_SIZE + SIZE_T_ONE);
    1.17 +      asize = granularity_align(nb - m->topsize + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE);
    1.18        /* Use mem here only if it did continuously extend old space */
    1.19        if (asize < HALF_MAX_SIZE_T &&
    1.20            (br = (char*)(CALL_MORECORE(asize))) == ss->base+ss->size) {
    1.21 @@ -3435,7 +3435,7 @@
    1.22        if (br != CMFAIL) {    /* Try to use/extend the space we did get */
    1.23          if (asize < HALF_MAX_SIZE_T &&
    1.24              asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) {
    1.25 -          size_t esize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE - asize);
    1.26 +          size_t esize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE - asize);
    1.27            if (esize < HALF_MAX_SIZE_T) {
    1.28              char* end = (char*)CALL_MORECORE(esize);
    1.29              if (end != CMFAIL)
    1.30 @@ -3459,7 +3459,7 @@
    1.31    }
    1.32  
    1.33    if (HAVE_MMAP && tbase == CMFAIL) {  /* Try MMAP */
    1.34 -    size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE;
    1.35 +    size_t req = nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE;
    1.36      size_t rsize = granularity_align(req);
    1.37      if (rsize > nb) { /* Fail if wraps around zero */
    1.38        char* mp = (char*)(CALL_MMAP(rsize));
    1.39 @@ -3472,7 +3472,7 @@
    1.40    }
    1.41  
    1.42    if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */
    1.43 -    size_t asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);
    1.44 +    size_t asize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE);
    1.45      if (asize < HALF_MAX_SIZE_T) {
    1.46        char* br = CMFAIL;
    1.47        char* end = CMFAIL;