mfunyu / malloc

Find out the workings behind optimum memory management and recode it, as well as free and realloc.
2 stars 0 forks source link

[bug] freelist block placed in a wrong size #37

Closed mfunyu closed 7 months ago

mfunyu commented 7 months ago
    index = get_index_by_size(size);
    if (!freelist[index])
        return (NULL);
    chunk = freelist[index];
    if (CHUNKSIZE(chunk) > MIN_CHUNKSIZE + size)
    {
        SD("size", size);
        SD("index", index);
        SD("chunk", CHUNKSIZE(chunk));
        SP("chunk", chunk);
        show_alloc_mem_ex();
    }
size : 528
index : 33
chunk : 1552
chunk : 0x7f3b3114daf0

Reproduction

$> make
$> ./test/run_test.sh 14
$> MallocShowHeap=1 LD_PRELOAD=./libft_malloc.so LD_LIBRARY_PATH=. ./correction 2> f
mfunyu commented 7 months ago

It was caused by the false categorization of size when freeed