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

[segfault] wrong chunk size on size 16 #14

Closed mfunyu closed 8 months ago

mfunyu commented 8 months ago
void    main()
{
    ft_printf("=== test9 jsut size for space left malloc ===\n");

    void    *ptr1 = malloc(16);
    void    *ptr2 = malloc(16);
    free(ptr1);
    free(ptr2);
}
TINY: 
0x7f0a3bb85000 ~ 0x7f0a3bb9e000 (102400 bytes)
==================++==========================+
 0x7f0a3bb85000   ||                          |
------------------++--------------------------+
 0x7f0a3bb85008   ||     16 (   0x18) | 1 | 0 | size
------------------++--------------------------+
 0x7f0a3bb85010   ||           0x7f0a3bb85030 | fd
------------------++--------------------------+
 0x7f0a3bb85018   ||                     0x18 | bk
==================++==========================+
 0x7f0a3bb85018   ||                     0x18 | prev_size
------------------++--------------------------+
 0x7f0a3bb85020   ||     16 (   0x18) | 0 | 1 | size
------------------++--------------------------+
 0x7f0a3bb85028   ||                          | mem
 0x7f0a3bb85030   ||                          |
==================++==========================+
 0x7f0a3bb85030   ||                          |
------------------++--------------------------+
 0x7f0a3bb85038   || 102320 (0x18fb8) | 1 | 0 | size
------------------++--------------------------+
 0x7f0a3bb85040   ||                      0x0 | fd
------------------++--------------------------+
 0x7f0a3bb85048   ||           0x7f0a3bb85000 | bk
------------------++--------------------------+
 0x7f0a3bb85050   ||                          |
                  || [    102296 (  0x18f98)] |
==================++==========================+
 0x7f0a3bb9dfe8   ||                      0x0 | prev_size
------------------++--------------------------+
 0x7f0a3bb9dff0   ||     -8 (    0x0) | 0 | 1 | size
------------------++--------------------------+
 0x7f0a3bb9dff8   ||                      0x0 | fd
==================++==========================+
Chunk Free
----------------+-------------+----------------+----------------+
 0x7f0a3bb85000 |  26 ( 0x1a) | 0x7f0a3bb85030 |           0x18 | 
----------------+-------------+----------------+----------------+
 0x7f0a3bb85030 | 102330 (0x18fba) |            0x0 | 0x7f0a3bb85000 | 
----------------+-------------+----------------+----------------+