marimlem / minishell

0 stars 0 forks source link

bug: sigpipe: falsecmd | falsecmd #45

Closed marimlem closed 3 months ago

marimlem commented 3 months ago

write in readline is segfaulting and causing leaks

minishell:$ abc | desf
minishell: command not found: desf
minishell: command not found: desf
==29085== 
==29085== HEAP SUMMARY:
==29085==     in use at exit: 205,316 bytes in 260 blocks
==29085==   total heap usage: 2,000 allocs, 1,740 frees, 258,898 bytes allocated
==29085== 
==29085== LEAK SUMMARY:
==29085==    definitely lost: 0 bytes in 0 blocks
==29085==    indirectly lost: 0 bytes in 0 blocks
==29085==      possibly lost: 0 bytes in 0 blocks
==29085==    still reachable: 0 bytes in 0 blocks
==29085==         suppressed: 205,316 bytes in 260 blocks
==29085== 
==29085== For lists of detected and suppressed errors, rerun with: -s
==29085== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==29086== 
==29086== HEAP SUMMARY:
==29086==     in use at exit: 205,316 bytes in 260 blocks
==29086==   total heap usage: 2,000 allocs, 1,740 frees, 258,898 bytes allocated
==29086== 
==29086== LEAK SUMMARY:
==29086==    definitely lost: 0 bytes in 0 blocks
==29086==    indirectly lost: 0 bytes in 0 blocks
==29086==      possibly lost: 0 bytes in 0 blocks
==29086==    still reachable: 0 bytes in 0 blocks
==29086==         suppressed: 205,316 bytes in 260 blocks
==29086== 
==29086== For lists of detected and suppressed errors, rerun with: -s
==29086== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==29084== 
==29084== Process terminating with default action of signal 13 (SIGPIPE)
==29084==    at 0x49BF077: write (write.c:26)
==29084==    by 0x493FE8C: _IO_file_write@@GLIBC_2.2.5 (fileops.c:1181)
==29084==    by 0x4941950: new_do_write (fileops.c:449)
==29084==    by 0x4941950: _IO_new_do_write (fileops.c:426)
==29084==    by 0x4941950: _IO_do_write@@GLIBC_2.2.5 (fileops.c:423)
==29084==    by 0x493F477: _IO_file_sync@@GLIBC_2.2.5 (fileops.c:799)
==29084==    by 0x49333C5: fflush (iofflush.c:40)
==29084==    by 0x488C879: rl_redisplay (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.0)
==29084==    by 0x48760F6: readline_internal_setup (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.0)
==29084==    by 0x48774D3: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.0)
==29084==    by 0x10CAAE: inputparsing (lu_inputparsing.c:25)
==29084==    by 0x109695: main (main.c:45)
==29084== 
==29084== HEAP SUMMARY:
==29084==     in use at exit: 210,586 bytes in 454 blocks
==29084==   total heap usage: 2,003 allocs, 1,549 frees, 258,932 bytes allocated
==29084== 
==29084== 8 bytes in 1 blocks are still reachable in loss record 2 of 72
==29084==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==29084==    by 0x11139A: ft_calloc (ft_calloc.c:21)
==29084==    by 0x1095D3: main (main.c:25)
==29084== 
==29084== 16 bytes in 1 blocks are still reachable in loss record 10 of 72
==29084==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==29084==    by 0x110BF1: ft_strdup (ft_strdup.c:26)
==29084==    by 0x10F01F: ft_add_list (env_utils.c:59)
==29084==    by 0x10F6D1: ft_add_key_and_value (key_value_utils.c:57)
==29084==    by 0x10F77A: ft_assign_key_and_value (key_value_utils.c:71)
==29084==    by 0x10964B: main (main.c:36)
==29084== 
==29084== 17 bytes in 1 blocks are still reachable in loss record 12 of 72
==29084==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==29084==    by 0x110BF1: ft_strdup (ft_strdup.c:26)
==29084==    by 0x10F00C: ft_add_list (env_utils.c:58)
==29084==    by 0x10F6D1: ft_add_key_and_value (key_value_utils.c:57)
==29084==    by 0x10F77A: ft_assign_key_and_value (key_value_utils.c:71)
==29084==    by 0x10964B: main (main.c:36)
==29084== 
==29084== 24 bytes in 1 blocks are still reachable in loss record 15 of 72
==29084==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==29084==    by 0x11139A: ft_calloc (ft_calloc.c:21)
==29084==    by 0x1095F7: main (main.c:28)
==29084== 
==29084== 128 bytes in 1 blocks are still reachable in loss record 25 of 72
==29084==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==29084==    by 0x11139A: ft_calloc (ft_calloc.c:21)
==29084==    by 0x1095AF: main (main.c:21)
==29084== 
==29084== 819 bytes in 63 blocks are still reachable in loss record 35 of 72
==29084==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==29084==    by 0x110BF1: ft_strdup (ft_strdup.c:26)
==29084==    by 0x10F0AB: ft_add_list (env_utils.c:73)
==29084==    by 0x10F6D1: ft_add_key_and_value (key_value_utils.c:57)
==29084==    by 0x10F77A: ft_assign_key_and_value (key_value_utils.c:71)
==29084==    by 0x10964B: main (main.c:36)
==29084== 
==29084== 1,512 bytes in 63 blocks are still reachable in loss record 42 of 72
==29084==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==29084==    by 0x11139A: ft_calloc (ft_calloc.c:21)
==29084==    by 0x10F090: ft_add_list (env_utils.c:70)
==29084==    by 0x10F6D1: ft_add_key_and_value (key_value_utils.c:57)
==29084==    by 0x10F77A: ft_assign_key_and_value (key_value_utils.c:71)
==29084==    by 0x10964B: main (main.c:36)
==29084== 
==29084== 2,746 bytes in 63 blocks are still reachable in loss record 47 of 72
==29084==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==29084==    by 0x110BF1: ft_strdup (ft_strdup.c:26)
==29084==    by 0x10F0BE: ft_add_list (env_utils.c:74)
==29084==    by 0x10F6D1: ft_add_key_and_value (key_value_utils.c:57)
==29084==    by 0x10F77A: ft_assign_key_and_value (key_value_utils.c:71)
==29084==    by 0x10964B: main (main.c:36)
==29084== 
==29084== LEAK SUMMARY:
==29084==    definitely lost: 0 bytes in 0 blocks
==29084==    indirectly lost: 0 bytes in 0 blocks
==29084==      possibly lost: 0 bytes in 0 blocks
==29084==    still reachable: 5,270 bytes in 194 blocks
==29084==         suppressed: 205,316 bytes in 260 blocks
==29084== 
==29084== For lists of detected and suppressed errors, rerun with: -s
==29084== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
marimlem commented 3 months ago

fixed segfault and leaks by catching "else" after failed execve, but now only one command not found message

minishell:$ abc | def
minishell: command not found: def
==30760== 
==30760== HEAP SUMMARY:
==30760==     in use at exit: 204,631 bytes in 218 blocks
==30760==   total heap usage: 881 allocs, 663 frees, 240,148 bytes allocated
==30760== 
==30760== LEAK SUMMARY:
==30760==    definitely lost: 0 bytes in 0 blocks
==30760==    indirectly lost: 0 bytes in 0 blocks
==30760==      possibly lost: 0 bytes in 0 blocks
==30760==    still reachable: 0 bytes in 0 blocks
==30760==         suppressed: 204,631 bytes in 218 blocks
==30760== 
==30760== For lists of detected and suppressed errors, rerun with: -s
==30760== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==30761== 
==30761== HEAP SUMMARY:
==30761==     in use at exit: 204,631 bytes in 218 blocks
==30761==   total heap usage: 881 allocs, 663 frees, 240,148 bytes allocated
==30761== 
==30761== LEAK SUMMARY:
==30761==    definitely lost: 0 bytes in 0 blocks
==30761==    indirectly lost: 0 bytes in 0 blocks
==30761==      possibly lost: 0 bytes in 0 blocks
==30761==    still reachable: 0 bytes in 0 blocks
==30761==         suppressed: 204,631 bytes in 218 blocks
==30761== 
==30761== For lists of detected and suppressed errors, rerun with: -s
==30761== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
marimlem commented 3 months ago

fixed: duplicated "command not found handling" as else