lib/fileutils: close fd if fdopen is failed
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
This commit is contained in:
parent
f6c1168925
commit
c8d931ebe2
|
@ -34,10 +34,15 @@ static inline FILE *fopen_at(int dir, const char *filename,
|
||||||
int flags, const char *mode)
|
int flags, const char *mode)
|
||||||
{
|
{
|
||||||
int fd = openat(dir, filename, flags);
|
int fd = openat(dir, filename, flags);
|
||||||
|
FILE *ret;
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return fdopen(fd, mode);
|
ret = fdopen(fd, mode);
|
||||||
|
if (!ret)
|
||||||
|
close(fd);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue