diff --git a/CHANGES b/CHANGES index 6cbb845..884c1d0 100644 --- a/CHANGES +++ b/CHANGES @@ -35,6 +35,7 @@ Modules/ * Fix several compiler warnings * Fix memory leak in whoami * Fix internal error handling of LDAPControl_to_List() +* Fix two memory leaks and release GIL in encode_assertion_control and, thanks to Michael Ströder: * removed unused code schema.c * moved code from version.c to ldapmodule.c diff --git a/Modules/ldapcontrol.c b/Modules/ldapcontrol.c index 5cd30f9..9522d57 100644 --- a/Modules/ldapcontrol.c +++ b/Modules/ldapcontrol.c @@ -343,16 +343,33 @@ encode_assertion_control(PyObject *self, PyObject *args) goto endlbl; } + /* XXX: ldap_create() is a nasty and slow hack. It's creating a full blown + * LDAP object just to encode assertion controls. + */ + Py_BEGIN_ALLOW_THREADS err = ldap_create(&ld); + Py_END_ALLOW_THREADS + if (err != LDAP_SUCCESS) return LDAPerror(ld, "ldap_create"); err = ldap_create_assertion_control_value(ld,assertion_filterstr,&ctrl_val); - if (err != LDAP_SUCCESS) - return LDAPerror(ld, "ldap_create_assertion_control_value"); - res = LDAPberval_to_object(&ctrl_val); + if (err != LDAP_SUCCESS) { + LDAPerror(ld, "ldap_create_assertion_control_value"); + Py_BEGIN_ALLOW_THREADS + ldap_unbind_ext(ld, NULL, NULL); + Py_END_ALLOW_THREADS + return NULL; + } + Py_BEGIN_ALLOW_THREADS + ldap_unbind_ext(ld, NULL, NULL); + Py_END_ALLOW_THREADS + res = LDAPberval_to_object(&ctrl_val); + if (ctrl_val.bv_val != NULL) { + ber_memfree(ctrl_val.bv_val); + } endlbl: return res; @@ -371,5 +388,3 @@ LDAPinit_control(PyObject *d) { LDAPadd_methods(d, methods); } - -