libc_noux: close fd on failed O_TRUNC attempt

Fixes #3524.
This commit is contained in:
Josef Söntgen 2019-10-09 13:25:06 +02:00 committed by Christian Helmuth
parent 7b0771659e
commit ba9b612c4f

View File

@ -1242,8 +1242,10 @@ namespace {
Libc::Plugin_context *context = noux_context(sysio()->open_out.fd); Libc::Plugin_context *context = noux_context(sysio()->open_out.fd);
Libc::File_descriptor *fd = Libc::File_descriptor *fd =
Libc::file_descriptor_allocator()->alloc(this, context, sysio()->open_out.fd); Libc::file_descriptor_allocator()->alloc(this, context, sysio()->open_out.fd);
if ((flags & O_TRUNC) && (ftruncate(fd, 0) == -1)) if ((flags & O_TRUNC) && (ftruncate(fd, 0) == -1)) {
Plugin::close(fd);
return 0; return 0;
}
return fd; return fd;
} }