apply: don't leak fd on fdopen() error
PATCH 1/1 apply: don't leak fd on fdopen() error
Signed-off-by René Scharfe <[email protected]>
--- apply.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
apply.c +5 -2
@@ -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
Quoted 10 lines · René Scharfe
Signed-off-by René Scharfe <[email protected]>--- apply.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)apply.c +0
-0
apply.c static int write_out_one_reject(struct apply_state *state, struct patch *patch) · line 4662
Quoted 10 lines
apply.c +5
-2@@ -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.
Quoted 5 lines
apply.c +0
-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