* [PATCH] apply: don't leak fd on fdopen() error
@ 2024-04-05 10:58 René Scharfe
2024-04-05 17:09 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2024-04-05 10:58 UTC (permalink / raw
To: Git List
Signed-off-by: René Scharfe <l.s.r@web.de>
---
apply.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/apply.c b/apply.c
index 432837a674..1cfbc2f074 100644
--- a/apply.c
+++ b/apply.c
@@ -4655,8 +4655,11 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
return error_errno(_("cannot open %s"), namebuf);
}
rej = fdopen(fd, "w");
- if (!rej)
- return error_errno(_("cannot open %s"), namebuf);
+ if (!rej) {
+ error_errno(_("cannot open %s"), namebuf);
+ close(fd);
+ return -1;
+ }
/* Normal git tools never deal with .rej, so do not pretend
* this is a git patch by saying --git or giving extended
--
2.44.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] apply: don't leak fd on fdopen() error
2024-04-05 10:58 [PATCH] apply: don't leak fd on fdopen() error René Scharfe
@ 2024-04-05 17:09 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2024-04-05 17:09 UTC (permalink / raw
To: René Scharfe; +Cc: Git List
René Scharfe <l.s.r@web.de> writes:
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> apply.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/apply.c b/apply.c
> index 432837a674..1cfbc2f074 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -4655,8 +4655,11 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
> return error_errno(_("cannot open %s"), namebuf);
> }
> rej = fdopen(fd, "w");
> - if (!rej)
> - return error_errno(_("cannot open %s"), namebuf);
> + if (!rej) {
> + error_errno(_("cannot open %s"), namebuf);
> + close(fd);
> + return -1;
> + }
Ah, true, this fd is what we created in this function, and we should
close it. Well spotted.
Will queue.
>
> /* Normal git tools never deal with .rej, so do not pretend
> * this is a git patch by saying --git or giving extended
> --
> 2.44.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-05 17:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-05 10:58 [PATCH] apply: don't leak fd on fdopen() error René Scharfe
2024-04-05 17:09 ` Junio C Hamano
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.