nwrap: Avoid dclose(RTLD_NEXT) In case the libc was not found and RTLD_NEXT is used instead, we should not dlclose it, otherwise mayhem happens. Signed-off-by: Samuel Thibault diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c index 07c9757..b95afdf 100644 --- a/src/nss_wrapper.c +++ b/src/nss_wrapper.c @@ -6499,13 +6499,25 @@ void nwrap_destructor(void) /* libc */ if (m->libc != NULL) { - if (m->libc->handle != NULL) { + if (m->libc->handle != NULL +#ifdef RTLD_NEXT + && m->libc->handle != RTLD_NEXT +#endif + ) { dlclose(m->libc->handle); } - if (m->libc->nsl_handle != NULL) { + if (m->libc->nsl_handle != NULL +#ifdef RTLD_NEXT + && m->libc->nsl_handle != RTLD_NEXT +#endif + ) { dlclose(m->libc->nsl_handle); } - if (m->libc->sock_handle != NULL) { + if (m->libc->sock_handle != NULL +#ifdef RTLD_NEXT + && m->libc->sock_handle != RTLD_NEXT +#endif + ) { dlclose(m->libc->sock_handle); } SAFE_FREE(m->libc);