From 329ab80d1df4af42251917b5ae25564ade315e06 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 5 Apr 2016 19:08:25 +0200 Subject: [PATCH] libc: never destruct the file-descriptor allocator This patch prevents the destruction of the fd allocator when the program exists. Otherwise, the meta data for file descriptors that were not manually closed would vanish, which may cause problems in subsequent destructors. --- repos/libports/src/lib/libc/fd_alloc.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/repos/libports/src/lib/libc/fd_alloc.cc b/repos/libports/src/lib/libc/fd_alloc.cc index 89a3b32f2f..44705926cf 100644 --- a/repos/libports/src/lib/libc/fd_alloc.cc +++ b/repos/libports/src/lib/libc/fd_alloc.cc @@ -13,6 +13,7 @@ */ /* Genode includes */ +#include #include #include @@ -23,8 +24,14 @@ namespace Libc { File_descriptor_allocator *file_descriptor_allocator() { - static File_descriptor_allocator _file_descriptor_allocator; - return &_file_descriptor_allocator; + static bool constructed = 0; + static char placeholder[sizeof(File_descriptor_allocator)]; + if (!constructed) { + Genode::construct_at(placeholder); + constructed = 1; + } + + return reinterpret_cast(placeholder); } }