Skip to content

to close or not to close #1

@ReivenIV

Description

@ReivenIV

Hi Marcos,

I had a discution with collegues related to your pipex bonus related ton the line main_bonus/line_87

Should you close or not the STDIN_FILENO at the end of the process or not.. Well if you want to create a bash expirience you shouldn't because in some cases in bash like cat | cat | ls.. the program will listen some inputs from the user.. While pipex don't demande that kind of behavior because it has its own infile at the begining closing it will not create any problem or leak.

So the projet works but if you want to recreate a bash "altruistic" expirience i propose to erase line 87.

valgrind reports with close (2 FDs open):

➜  pipex__alissonmarcs valgrind --track-fds=yes ./pipex_bonus Makefile ls cat output
==4714== Memcheck, a memory error detector
==4714== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==4714== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==4714== Command: ./pipex_bonus Makefile ls cat output
==4714== 
==4714== 
==4714== FILE DESCRIPTORS: 2 open (2 std) at exit.
==4714== 
==4714== HEAP SUMMARY:
==4714==     in use at exit: 0 bytes in 0 blocks
==4714==   total heap usage: 10 allocs, 10 frees, 179 bytes allocated
==4714== 
==4714== All heap blocks were freed -- no leaks are possible
==4714== 
==4714== For lists of detected and suppressed errors, rerun with: -s
==4714== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

without closing (3 FD open) :

➜  pipex__alissonmarcs valgrind --track-fds=yes ./pipex_bonus Makefile ls cat output
==4825== Memcheck, a memory error detector
==4825== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==4825== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==4825== Command: ./pipex_bonus Makefile ls cat output
==4825== 
==4825== 
==4825== FILE DESCRIPTORS: 3 open (3 std) at exit.
==4825== 
==4825== HEAP SUMMARY:
==4825==     in use at exit: 0 bytes in 0 blocks
==4825==   total heap usage: 10 allocs, 10 frees, 179 bytes allocated
==4825== 
==4825== All heap blocks were freed -- no leaks are possible
==4825== 
==4825== For lists of detected and suppressed errors, rerun with: -s
==4825== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Other feedbacks:

  • even if you code is strait foward ->Add comments to your code. I'm sure 2 years after is hard to come back.
  • Your make file when make re is not compiling the bonus.

Please don't take it personal, i'm looking to understand the project and not judging yours. I'm looking for feedbacks and learn and don't hesitate to bring more information to these topic.

Good luck.
Greetings from 42 france

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions