Changeset 49 for trunk/xcache.c


Ignore:
Timestamp:
2006-05-30T04:05:58+02:00 (8 years ago)
Author:
moo
Message:

big diff yet small change: fix ran into outside of shared memory. and commit the test that figure it out.
valgrind rocks even for our code for shared memory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xcache.c

    r39 r49  
    892892    xc_mem_t *mem; 
    893893    int i; 
    894  
    895     xc_memsize_t memsize = shmsize / hcache->size; 
     894    xc_memsize_t memsize; 
     895 
     896    memsize = shmsize / hcache->size; 
     897 
     898    /* Don't let it break out of mem after ALIGNed 
     899     * This is important for  
     900     * Simply loop until it fit our need 
     901     */ 
     902    while (ALIGN(memsize) * hcache->size > shmsize && ALIGN(memsize) != memsize) { 
     903        if (memsize < ALIGN(1)) { 
     904            CHECK(NULL, "cache too small"); 
     905        } 
     906        memsize --; 
     907    } 
    896908 
    897909    CHECK(caches = calloc(hcache->size, sizeof(xc_cache_t *)), "caches OOM"); 
    898910 
    899911    for (i = 0; i < hcache->size; i ++) { 
    900         mem = xc_mem_init(ptr, memsize); 
    901         ptr += ALIGN(memsize); 
     912        CHECK(mem            = xc_mem_init(ptr, memsize), "Failed init memory allocator"); 
     913        ptr += memsize; 
    902914        CHECK(cache          = xc_mem_calloc(mem, 1, sizeof(xc_cache_t)), "cache OOM"); 
    903915        CHECK(cache->entries = xc_mem_calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); 
Note: See TracChangeset for help on using the changeset viewer.