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] inf. loop in show heap #10

Closed mfunyu closed 9 months ago

mfunyu commented 9 months ago
$> MallocShowHeap=1 ./test_malloc

 0x7f515198cfe8   ||                      0x0 | prev_size
------------------++--------------------------+
 0x7f515198cff0   ||     -8 (    0x0) | 0 | 0 | size
------------------++--------------------------+
 0x7f515198cff8   ||                      0x0 | fd
------------------++--------------------------+
 0x7f515198d000   ||                      0x0 | bk
------------------++--------------------------+
 0x7f515198d008   ||                          |
                  || [       -32 (0xffffffffffffffe0)] |
==================++==========================+
 0x7f515198cfe8   ||                      0x0 | prev_size
------------------++--------------------------+
 0x7f515198cff0   ||     -8 (    0x0) | 0 | 0 | size
------------------++--------------------------+
 0x7f515198cff8   ||                      0x0 | fd
------------------++--------------------------+
 0x7f515198d000   ||                      0x0 | bk
------------------++--------------------------+
 0x7f515198d008   ||                          |
                  || [       -32 (0xffffffffffffffe0)] |
==================++==========================+
 0x7f515198cfe8   ||                      0x0 | prev_size
------------------++--------------------------+
 0x7f515198cff0   ||     -8 (    0x0) | 0 | 0 | size
------------------++--------------------------+
 0x7f515198cff8   ||                      0x0 | fd
------------------++--------------------------+
 0x7f515198d000   ||                      0x0 | bk
------------------++--------------------------+
 0x7f515198d008   ||                          |
                  || [       -32 (0xffffffffffffffe0)] |
==================++==========================+
 0x7f515198cfe8   ||                      0x0 | prev_size
------------------++--------------------------+
 0x7f515198cff0   ||     -8 (    0x0) | 0 | 0 | size
------------------++--------------------------+
 0x7f515198cff8   ||                      0x0 | fd
------------------++--------------------------+
 0x7f515198d000   ||                      0x0 | bk
------------------++--------------------------+
 0x7f515198d008   ||                          |
                  || [       -32 (0xffffffffffffffe0)] |
==================++==========================+
 0x7f515198cfe8   ||                      0x0 | prev_size
------------------++--------------------------+
 0x7f515198cff0   ||     -8 (    0x0) | 0 | 0 | size
------------------++--------------------------+
 0x7f515198cff8   ||                      0x0 | fd
mfunyu commented 9 months ago
#include <stdio.h>
#include <string.h>
#include "malloc.h"
#include "ft_printf.h"

void    malloc_alot()
{
    void    *ptr[104];
    for (int i = 0; i < 104; i++)
        ptr[i] = malloc(1000);
    ptr[2] = malloc(570);
}

void    main()
{
    malloc_alot();
    malloc(32);
    malloc(32);
    malloc(32);
    malloc(48);
}