mirror of
https://https.git.savannah.gnu.org/git/findutils.git
synced 2026-01-26 15:39:06 +00:00
Avoid an fd leak in fopen_cloexec_for_read_only.
* xargs/xargs.c (fopen_cloexec_for_read_only): when fdopen fails, close the file descriptor instead of leaking it. Also, use GNU-style brace positioning. Both problems were noticed by Paul Eggert.
This commit is contained in:
parent
9ebef301ac
commit
d286cf67dd
@ -367,9 +367,24 @@ smaller_of (size_t a, size_t b)
|
||||
}
|
||||
|
||||
|
||||
static FILE* fopen_cloexec_for_read_only (const char *file_name) {
|
||||
static FILE* fopen_cloexec_for_read_only (const char *file_name)
|
||||
{
|
||||
int fd = open_cloexec (file_name, O_RDONLY);
|
||||
return (fd < 0) ? NULL : fdopen (fd, "r");
|
||||
if (fd < 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE *result = fdopen (fd, "r");
|
||||
if (!result)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
close (fd);
|
||||
errno = saved_errno;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user