Skip to content

Commit 9f86c06

Browse files
tiranencukou
authored andcommitted
Fix two memory leaks in encode_assertion_control
encode_assertion_control was leaking a LDAP* struct and BER data values on every call. Both data structures are now properly freed and the GIL is released around ldap_create() and ldap_unbind_s(). Closes: python-ldap#79 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent c86b8e9 commit 9f86c06

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Modules/
3535
* Fix several compiler warnings
3636
* Fix memory leak in whoami
3737
* Fix internal error handling of LDAPControl_to_List()
38+
* Fix two memory leaks and release GIL in encode_assertion_control
3839
and, thanks to Michael Ströder:
3940
* removed unused code schema.c
4041
* moved code from version.c to ldapmodule.c

Modules/ldapcontrol.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,33 @@ encode_assertion_control(PyObject *self, PyObject *args)
343343
goto endlbl;
344344
}
345345

346+
/* XXX: ldap_create() is a nasty and slow hack. It's creating a full blown
347+
* LDAP object just to encode assertion controls.
348+
*/
349+
Py_BEGIN_ALLOW_THREADS
346350
err = ldap_create(&ld);
351+
Py_END_ALLOW_THREADS
352+
347353
if (err != LDAP_SUCCESS)
348354
return LDAPerror(ld, "ldap_create");
349355

350356
err = ldap_create_assertion_control_value(ld,assertion_filterstr,&ctrl_val);
351-
if (err != LDAP_SUCCESS)
352-
return LDAPerror(ld, "ldap_create_assertion_control_value");
353357

354-
res = LDAPberval_to_object(&ctrl_val);
358+
if (err != LDAP_SUCCESS) {
359+
LDAPerror(ld, "ldap_create_assertion_control_value");
360+
Py_BEGIN_ALLOW_THREADS
361+
ldap_unbind_ext(ld, NULL, NULL);
362+
Py_END_ALLOW_THREADS
363+
return NULL;
364+
}
365+
Py_BEGIN_ALLOW_THREADS
366+
ldap_unbind_ext(ld, NULL, NULL);
367+
Py_END_ALLOW_THREADS
355368

369+
res = LDAPberval_to_object(&ctrl_val);
370+
if (ctrl_val.bv_val != NULL) {
371+
ber_memfree(ctrl_val.bv_val);
372+
}
356373
endlbl:
357374

358375
return res;
@@ -371,5 +388,3 @@ LDAPinit_control(PyObject *d)
371388
{
372389
LDAPadd_methods(d, methods);
373390
}
374-
375-

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy