1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-25 16:47:38 +01:00

Do not try to close invalid fds

This was found by Valgrind:

==8330== Warning: invalid file descriptor -1 in syscall close()
==8330==    at 0x504B9F4: close (in /usr/lib/libpthread-2.26.so)
==8330==    by 0x40914DA: open_pipe (Ginit.c:82)
==8330==    by 0x40914DA: _ULx86_64_init_mem_validate (Ginit.c:154)
==8330==    by 0x4090CFE: _ULx86_64_init (Gglobal.c:93)
==8330==    by 0x4090A8C: _ULx86_64_set_caching_policy (Gset_caching_policy.c:32)
This commit is contained in:
Milian Wolff 2018-04-24 15:30:59 +02:00 committed by Milian Wolff
parent 2bb51aa4fd
commit b256722d49

View file

@ -78,9 +78,10 @@ static int mem_validate_pipe[2] = {-1, -1};
static inline void
open_pipe (void)
{
/* ignore errors for closing invalid fd's */
close (mem_validate_pipe[0]);
close (mem_validate_pipe[1]);
if (mem_validate_pipe[0] != -1)
close (mem_validate_pipe[0]);
if (mem_validate_pipe[1] != -1)
close (mem_validate_pipe[1]);
pipe2 (mem_validate_pipe, O_CLOEXEC | O_NONBLOCK);
}