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

[crush] unterminated free #56

Closed mfunyu closed 5 months ago

mfunyu commented 5 months ago
$>  LD_PRELOAD=./libft_malloc.so MallocDebug=1 gcc -I includes -I libft -I ft_printf -I . ./test/single_test/test2.c -L. -lft_malloc -Llibft -lft -Lft_printf -lftprintf -o single_test
...
[   free] by bfd_close_all_done : free(0x7fdbe762f980) -> terminated
[   free] by bfd_close_all_done : free(0x7fdbe762faf0) -> terminated
[ malloc] by _objalloc_alloc : malloc(4064) = 0x7fdbe7d94810
[ malloc] by _objalloc_alloc : malloc(4064) = 0x7fdbe7d95810
[ malloc] by _objalloc_alloc : malloc(4064) = 0x7fdbe7d96810
[ malloc] by bfd_get_full_section_contents : malloc(464) = 0x7fdbe762fd00
[ malloc] by _objalloc_alloc : malloc(32552) = 0x7fdbe7d97810
[   free] by bfd_elf_link_add_symbols : free(0x7fdbe762fd00) -> terminated
[ malloc] by bfd_elf_get_elf_syms : malloc(72552) = 0x7fdbe7cbac10
[ malloc] by bfd_elf_get_elf_syms : malloc(96736) = 0x7fdbe7d25a10
[   free] by bfd_elf_get_elf_syms : free(0x7fdbe7cbac10)[   free]                 : free(0x7f6e1a91b2d0) -> terminated
[   free]                 : free(0x7f6e1a91b2f0) -> terminated
[   free]                 : free(0x7f6e1a91b230) -> terminated
[ malloc]                 : malloc(50) = 0x7f6e1a91a060
[   free]                 : free(0x7f6e1a91a060) -> terminated
[ malloc]                 : malloc(5) = 0x7f6e1a91b310
...
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
mfunyu commented 5 months ago

not enough memory is allocated, probably header info is probably overwritten

[ malloc] by bfd_elf_get_elf_syms : malloc(72552) = 0x7f4c6c284c10
[ malloc] by bfd_elf_get_elf_syms : malloc(96736) = 0x7f4c6c2efa10
[   free] by bfd_elf_get_elf_syms : free(0x7f4c6c284c10)
freeing 0x7f4c6c284c10

freeing 0x7f4c6c284c00
max: 1040896
chunk: 0x7f4c6c284c00
chunk->size: 70145
mfunyu commented 5 months ago

20th (last) free call by bfd_elf_get_elf_syms

mfunyu commented 5 months ago

Within freeblocks, multiple sizes exist, need to choose bigger free block