copy_fd: close ifd on error
PATCH 1/1 copy_fd: close ifd on error
In copy_fd when write fails we ought to close input file descriptor.
Signed-off-by Sam Ravnborg <[email protected]>
---
Found while looking at the source for inspiration for something else. I did not see any error related to this.
Sam
copy.c +5 -2
@@ -22,11 +22,14 @@ int copy_fd(int ifd, int ofd) buf += written; len -= written; } -else if (!written) +else if (!written) { +close (ifd);return error ("copy-fd: write returned 0" ); -else + }else { +close (ifd);return error ("copy-fd: write returned %s" ,strerror (errno)); + } } }close (ifd);
Quoted 7 lines · Sam Ravnborg
In
copy_fdwhen write fails we ought to close input file descriptor.Signed-off-by Sam Ravnborg <[email protected]>---
Found while looking at the source for inspiration for something else. I did not see any error related to this.
Thanks. I think the only place this matters is git-local-fetch which nobody uses these days where it can leak handful ifd. All other users immediately exit upon seeing failure return from the function.
Of course this would matter much when we do libification.