bonsai icon indicating copy to clipboard operation
bonsai copied to clipboard

native memleak in `ldap-xplat.c` (`ldap_init_thread_func`)

Open dafanasiev opened this issue 9 months ago • 2 comments

In ldap-xplat.c#L714 you allocate LDAP.

  1. before ldap_initialize call just null LDAP*:
data->ld = NULL;
  1. ldap_set_option also calls can return other than LDAP_SUCCESS result, so we need to control this (for example):
...
    rc = ldap_set_option(data->ld, LDAP_OPT_REFERRALS, ref_opt);
    if (rc != LDAP_SUCCESS) {
        data->retval = rc;
        goto end;
    }
...
  1. and finally at the end label we need to free LDAP struct if we have problems (and allocate it):
end:
// added:
    if(data->retval != LDAP_SUCCESS){
        ldap_destroy(data->ld);
        data->ld = NULL;
    }

dafanasiev avatar Nov 23 '23 05:11 dafanasiev