gysiang / minishell

0 stars 1 forks source link

Memory Leaks #242

Open gysiang opened 4 days ago

gysiang commented 4 days ago
  1. Fix memory leaks when heredoc exits
  2. Test memory leaks for single and pipe command.
  3. Redirects -> have to clear memory when it exits from failed fd.
gysiang commented 4 days ago

minishell$ echo hi > no_permission.txt minishell: no_permission.txt: Permission denied ==1556315== ==1556315== FILE DESCRIPTORS: 3 open (3 std) at exit. ==1556315== ==1556315== HEAP SUMMARY: ==1556315== in use at exit: 204,215 bytes in 222 blocks ==1556315== total heap usage: 511 allocs, 289 frees, 230,215 bytes allocated ==1556315== ==1556315== LEAK SUMMARY: ==1556315== definitely lost: 0 bytes in 0 blocks ==1556315== indirectly lost: 0 bytes in 0 blocks ==1556315== possibly lost: 0 bytes in 0 blocks ==1556315== still reachable: 0 bytes in 0 blocks ==1556315== suppressed: 204,215 bytes in 222 blocks ==1556315== ==1556315== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) --1556315-- --1556315-- used_suppression: 63 leak readline ./readline.supp:2 suppressed: 204,215 bytes in 222 blocks ==1556315== ==1556315== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

axellee1994 commented 4 days ago

@gysiang I am encountering the same problem too. Will try to tackle again tomorrow afternoon

gysiang commented 4 days ago

minishell$ cat input.txt ==1556997== Memcheck, a memory error detector ==1556997== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==1556997== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==1556997== Command: /usr/bin/cat input.txt ==1556997== hi bye bye ==1556997== ==1556997== FILE DESCRIPTORS: 3 open (1 std) at exit. ==1556997== Open file descriptor 4: /dev/pts/0 ==1556997== ==1556997== ==1556997== Open file descriptor 3: /dev/pts/0 ==1556997== ==1556997== ==1556997== ==1556997== HEAP SUMMARY: ==1556997== in use at exit: 0 bytes in 0 blocks ==1556997== total heap usage: 31 allocs, 31 frees, 139,232 bytes allocated ==1556997== ==1556997== All heap blocks were freed -- no leaks are possible ==1556997== ==1556997== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

minishell$ cat < input.txt ==1556994== Memcheck, a memory error detector ==1556994== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==1556994== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==1556994== Command: /usr/bin/cat ==1556994== hi bye bye ==1556994== ==1556994== FILE DESCRIPTORS: 2 open (0 std) at exit. ==1556994== Open file descriptor 4: /dev/pts/0 ==1556994== ==1556994== ==1556994== Open file descriptor 3: /dev/pts/0 ==1556994==

gysiang commented 3 days ago

minishell$ echo hi > no_permission.txt | echo bye minishell: no_permission.txt: Permission denied bye ==1781449== ==1781449== FILE DESCRIPTORS: 3 open (3 std) at exit. ==1781449== ==1781449== HEAP SUMMARY: ==1781449== in use at exit: 204,226 bytes in 222 blocks ==1781449== total heap usage: 563 allocs, 341 frees, 231,162 bytes allocated ==1781449== ==1781449== LEAK SUMMARY: ==1781449== definitely lost: 0 bytes in 0 blocks ==1781449== indirectly lost: 0 bytes in 0 blocks ==1781449== possibly lost: 0 bytes in 0 blocks ==1781449== still reachable: 0 bytes in 0 blocks ==1781449== suppressed: 204,226 bytes in 222 blocks ==1781449== ==1781449== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) --1781449-- --1781449-- used_suppression: 63 leak readline ./readline.supp:2 suppressed: 204,226 bytes in 222 blocks ==1781449== ==1781449== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ==1781450== ==1781450== FILE DESCRIPTORS: 3 open (3 std) at exit. ==1781450== ==1781450== HEAP SUMMARY: ==1781450== in use at exit: 204,226 bytes in 222 blocks ==1781450== total heap usage: 558 allocs, 336 frees, 231,024 bytes allocated ==1781450== ==1781450== LEAK SUMMARY: ==1781450== definitely lost: 0 bytes in 0 blocks ==1781450== indirectly lost: 0 bytes in 0 blocks ==1781450== possibly lost: 0 bytes in 0 blocks ==1781450== still reachable: 0 bytes in 0 blocks ==1781450== suppressed: 204,226 bytes in 222 blocks ==1781450== ==1781450== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) --1781450-- --1781450-- used_suppression: 63 leak readline ./readline.supp:2 suppressed: 204,226 bytes in 222 blocks ==1781450==