From: Howard Chu Date: Sat, 9 Feb 2002 01:09:23 +0000 (+0000) Subject: Slightly better fix for library cleanup. Requires GCC. X-Git-Tag: OPENLDAP_REL_ENG_2_1_BP~81 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ffa4b2634389ecc129f59a1de05d44f62b6bb871;p=openldap Slightly better fix for library cleanup. Requires GCC. --- diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index 46f8f7768a..82778a79dd 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -364,6 +364,17 @@ static void openldap_ldap_init_w_env( } } +#if defined(__GNUC__) +/* Declare this function as a destructor so that it will automatically be + * invoked either at program exit (if libldap is a static library) or + * at unload time (if libldap is a dynamic library). + * + * Sorry, don't know how to handle this for non-GCC environments. + */ +static void ldap_int_destroy_global_options(void) + __attribute__ ((destructor)); +#endif + static void ldap_int_destroy_global_options(void) { @@ -396,11 +407,16 @@ void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl gopts->ldo_tm_api = (struct timeval *)NULL; gopts->ldo_tm_net = (struct timeval *)NULL; - /* ldo_defludp wll be freed by the atexit() handler + /* ldo_defludp will be freed by the termination handler */ ldap_url_parselist(&gopts->ldo_defludp, "ldap://localhost/"); gopts->ldo_defport = LDAP_PORT; +#if !defined(__GNUC__) && !defined(PIC) + /* Do this only for a static library, and only if we can't + * arrange for it to be executed as a library destructor + */ atexit(ldap_int_destroy_global_options); +#endif gopts->ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT; gopts->ldo_rebind_proc = NULL;