From 14a6dec3e2dc6a057d81582cf31ddcb07c6de97e Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Wed, 9 Apr 2014 13:19:08 -0600 Subject: [PATCH 197/225] Ticket #47773 - mem leak in do_bind when there is an error https://fedorahosted.org/389/ticket/47773 Reviewed by: nhosoi (Thanks!) Branch: 389-ds-base-1.2.11 Fix Description: Do not get the SLAPI_BIND_TARGET_SDN from the pblock and free it in the clean up code if it was never set in the pblock - just free the local variable sdn in this case. Platforms tested: RHEL6 x86_64 Flag Day: no Doc impact: no (cherry picked from commit 2a57b521b86b24c0f0a8ddfbea4169c71ee4e896) (cherry picked from commit c0606d45b91e87e4d0d90dec0812d20a0b23f545) (cherry picked from commit 39eab765d9c6552c246bed13903807eca4c96887) (cherry picked from commit 0911134c2c6d97243a7f6652a9a861bf7e28d91b) (cherry picked from commit 7655ff76c90651d817bfbd70313228c9818ad591) --- ldap/servers/slapd/bind.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ldap/servers/slapd/bind.c b/ldap/servers/slapd/bind.c index 97b236e..92d7965 100644 --- a/ldap/servers/slapd/bind.c +++ b/ldap/servers/slapd/bind.c @@ -131,6 +131,7 @@ do_bind( Slapi_PBlock *pb ) ber_tag_t ber_rc; int rc = 0; Slapi_DN *sdn = NULL; + int bind_sdn_in_pb = 0; /* is sdn set in the pb? */ Slapi_Entry *referral; char errorbuf[BUFSIZ]; char **supported, **pmech; @@ -369,6 +370,7 @@ do_bind( Slapi_PBlock *pb ) isroot = slapi_dn_isroot( slapi_sdn_get_ndn(sdn) ); slapi_pblock_set( pb, SLAPI_REQUESTOR_ISROOT, &isroot ); slapi_pblock_set( pb, SLAPI_BIND_TARGET_SDN, (void*)sdn ); + bind_sdn_in_pb = 1; /* pb now owns sdn */ slapi_pblock_set( pb, SLAPI_BIND_METHOD, &method ); slapi_pblock_set( pb, SLAPI_BIND_SASLMECHANISM, saslmech ); slapi_pblock_set( pb, SLAPI_BIND_CREDENTIALS, &cred ); @@ -861,7 +863,9 @@ account_locked: free_and_return:; if (be) slapi_be_Unlock(be); - slapi_pblock_get(pb, SLAPI_BIND_TARGET_SDN, &sdn); + if (bind_sdn_in_pb) { + slapi_pblock_get(pb, SLAPI_BIND_TARGET_SDN, &sdn); + } slapi_sdn_free(&sdn); slapi_ch_free_string( &saslmech ); slapi_ch_free( (void **)&cred.bv_val ); -- 1.8.1.4