ronachong/holbertonschool-low_level_programming

Simple shell - 67 allocs, 21 frees

Closed this issue · 1 comments

Report from Valgrind:

==5330==

==5330== HEAP SUMMARY:
==5330== in use at exit: 197,446 bytes in 46 blocks
==5330== total heap usage: 67 allocs, 21 frees, 197,904 bytes allocated
==5330==
==5330== 10 bytes in 1 blocks are definitely lost in loss record 1 of 7
==5330== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5330== by 0x400EC1: concat_string (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400E22: get_fp (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x4008F9: shell (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400874: main (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330==
==5330== 10 bytes in 2 blocks are definitely lost in loss record 2 of 7
==5330== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5330== by 0x401234: string_split (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x4009D9: get_argv (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x4008B0: shell (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400874: main (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330==
==5330== 89 bytes in 8 blocks are definitely lost in loss record 3 of 7
==5330== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5330== by 0x401234: string_split (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400A34: get_patharr (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x4008DF: shell (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400874: main (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330==
==5330== 118 (24 direct, 94 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 7
==5330== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5330== by 0x4011B7: string_split (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400A6F: get_pathstr (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400A07: get_patharr (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x4008DF: shell (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400874: main (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330==
==5330== 323 bytes in 26 blocks are definitely lost in loss record 6 of 7
==5330== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5330== by 0x401234: string_split (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400A6F: get_pathstr (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400A07: get_patharr (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x4008DF: shell (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400874: main (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330==
==5330== 196,896 bytes in 6 blocks are definitely lost in loss record 7 of 7
==5330== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5330== by 0x4EF3DD0: __alloc_dir (opendir.c:207)
==5330== by 0x400D93: get_fp (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x4008F9: shell (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330== by 0x400874: main (in /home/vagrant/holberton_repos/holbertonschool-low_level_programming/simple_shell/simple_shell)
==5330==
==5330== LEAK SUMMARY:
==5330== definitely lost: 197,352 bytes in 44 blocks
==5330== indirectly lost: 94 bytes in 2 blocks
==5330== possibly lost: 0 bytes in 0 blocks
==5330== still reachable: 0 bytes in 0 blocks
==5330== suppressed: 0 bytes in 0 blocks
==5330==

Issue was resolved by freeing a couple missed strings in small helper fxns, re-adding the free call for strings inside 2D arrays (in free_2Darr) and closing opened dirs (in get_fp). A null assignment for pointers already freed inside 2D arrays was also made to avoid double-freeing.

screen shot 2016-05-16 at 6 38 15 pm