[Date Prev][Date Next] [Chronological] [Thread] [Top]

atexit-handler causes segfault when dlopen-ed libldap is unloaded prior to program termination (ITS#1577)

Full_Name: Arne Georg Gleditsch
Version: 2.0.21
OS: GNU/Linux
Submission from: (NULL) (

openldap-2.0.21/libraries/libldap/init.c contains the statement  
"atexit(ldap_int_destroy_global_options)".  This causes programs
that load and unload libldap using dlopen to segfault upon termination because
one of the exit handlers reside in now unmapped memory.  Trivial example

#include <stdio.h>
#include <dlfcn.h>

int main() {
    void *(* ldap_init)(const char *, int);
    void *ldap = NULL;
    char *error;

    void *handle = dlopen("libldap.so.2", RTLD_LAZY);

    if (error = dlerror()) {
	printf("%s\n", error);

    ldap_init = dlsym(handle, "ldap_init");
    if (error = dlerror()) {
	printf("%s\n", error);

    printf("libldap loaded.\n");

    ldap_init("localhost", 389);


    printf("libldap unloaded.\n");

This is a real problem with pam-ldap, as su is now segfaulting at exit on my
systems. Other services are likely affected as well.