From ba9b612c4fe4d55e9c7a301142fbe32b578c8a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Wed, 9 Oct 2019 13:25:06 +0200 Subject: [PATCH] libc_noux: close fd on failed O_TRUNC attempt Fixes #3524. --- repos/ports/src/lib/libc_noux/plugin.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/repos/ports/src/lib/libc_noux/plugin.cc b/repos/ports/src/lib/libc_noux/plugin.cc index d0cf513dd..72e0971d1 100644 --- a/repos/ports/src/lib/libc_noux/plugin.cc +++ b/repos/ports/src/lib/libc_noux/plugin.cc @@ -1242,8 +1242,10 @@ namespace { Libc::Plugin_context *context = noux_context(sysio()->open_out.fd); Libc::File_descriptor *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 fd; }