diff mbox series

[4/5] copy_and_spawn_sgid: Avoid double calls to close()

Message ID 20210727174129.3612656-5-siddhesh@sourceware.org
State New
Headers show
Series Static analysis fixes | expand

Commit Message

Siddhesh Poyarekar July 27, 2021, 5:41 p.m. UTC
If close() on infd and outfd succeeded, reset the fd numbers so that
we don't attempt to close them again.
---
 support/support_capture_subprocess.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Arjun Shankar Aug. 3, 2021, 3:25 p.m. UTC | #1
Hi Siddhesh,

> If close() on infd and outfd succeeded, reset the fd numbers so that
> we don't attempt to close them again.
> ---
>  support/support_capture_subprocess.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/support/support_capture_subprocess.c b/support/support_capture_subprocess.c
> index 27bfd19c93..0bacf6dbc2 100644
> --- a/support/support_capture_subprocess.c
> +++ b/support/support_capture_subprocess.c
> @@ -170,6 +170,7 @@ copy_and_spawn_sgid (char *child_id, gid_t gid)
>       support_subprogram because we only want the program exit status, not the
>       contents.  */
>    ret = 0;
> +  infd = outfd = -1;
>  
>    char * const args[] = {execname, child_id, NULL};

Looks good to me.

infd and outfd are indeed close'd above, and close'd again below if they are
non-negative. Setting to -1 ensures that we won't attempt to close them again.

Reviewed-by: Arjun Shankar <arjun@redhat.com>

Cheers!
diff mbox series

Patch

diff --git a/support/support_capture_subprocess.c b/support/support_capture_subprocess.c
index 27bfd19c93..0bacf6dbc2 100644
--- a/support/support_capture_subprocess.c
+++ b/support/support_capture_subprocess.c
@@ -170,6 +170,7 @@  copy_and_spawn_sgid (char *child_id, gid_t gid)
      support_subprogram because we only want the program exit status, not the
      contents.  */
   ret = 0;
+  infd = outfd = -1;
 
   char * const args[] = {execname, child_id, NULL};