Issue 7806 - memory leak in contrib/ldapc++/LDAPAsynConnection.cpp
Summary: memory leak in contrib/ldapc++/LDAPAsynConnection.cpp
Status: VERIFIED FIXED
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: contrib (show other issues)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-26 18:15 UTC by kevpatt@khptech.com
Modified: 2022-04-11 19:14 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kevpatt@khptech.com 2014-02-26 18:15:30 UTC
Full_Name: Kevin H. Patterson
Version: git master HEAD
OS: macosx 10.9.1
URL: http://campus.hartland.edu/temp/0001-fixed-memory-leak-in-LDAPAsynConnection.cpp.patch
Submission from: (NULL) (65.207.4.130)


In libldapcpp, there is a memory leak in the LDAPAsynConnection class.
ldap_initialize() allocates memory which is never freed. This memory (ld
structure) should be freed by a call to ldap_unbind() in the class destructor
and other places where the ld structure is replaced with a new one.

I have included a patch against git master HEAD below.

---

From c9b4b1a2638eec20f35c2eae31f0471cc61a21ff Mon Sep 17 00:00:00 2001
From: "Kevin H. Patterson" <kevpatt@khptech.com>
Date: Wed, 26 Feb 2014 13:08:24 -0500
Subject: [PATCH] fixed memory leak in LDAPAsynConnection.cpp

---
 contrib/ldapc++/src/LDAPAsynConnection.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/contrib/ldapc++/src/LDAPAsynConnection.cpp
b/contrib/ldapc++/src/LDAPAsynConnection.cpp
index 894f8ba..582d2b5 100644
--- a/contrib/ldapc++/src/LDAPAsynConnection.cpp
+++ b/contrib/ldapc++/src/LDAPAsynConnection.cpp
@@ -43,7 +43,10 @@ LDAPAsynConnection::LDAPAsynConnection(const string& url, int
port,
     this->setConstraints(cons);
 }
 
-LDAPAsynConnection::~LDAPAsynConnection(){}
+LDAPAsynConnection::~LDAPAsynConnection(){
+	unbind();
+	delete m_constr;
+}
 
 void LDAPAsynConnection::init(const string& hostname, int port){
     DEBUG(LDAP_DEBUG_TRACE,"LDAPAsynConnection::init" << endl);
@@ -51,6 +54,8 @@ void LDAPAsynConnection::init(const string& hostname, int
port){
             "   hostname:" << hostname << endl
             << "   port:" << port << endl);
 
+	unbind();
+
     m_uri.setScheme("ldap");
     m_uri.setHost(hostname);
     m_uri.setPort(port);
@@ -66,6 +71,8 @@ void LDAPAsynConnection::init(const string& hostname, int
port){
 }
 
 void LDAPAsynConnection::initialize(const std::string& uri){
+	unbind();
+
 	m_uri.setURLString(uri);
     int ret = ldap_initialize(&cur_session, m_uri.getURLString().c_str());
     if ( ret != LDAP_SUCCESS ) {
@@ -277,6 +284,7 @@ void LDAPAsynConnection::unbind(){
 
 void LDAPAsynConnection::setConstraints(LDAPConstraints *cons){
     DEBUG(LDAP_DEBUG_TRACE,"LDAPAsynConnection::setConstraints()" << endl);
+	delete m_constr;
     m_constr=cons;
 }
 
-- 
1.8.3.4 (Apple Git-47)
Comment 1 Howard Chu 2014-02-26 19:08:05 UTC
kevpatt@khptech.com wrote:
> Full_Name: Kevin H. Patterson
> Version: git master HEAD
> OS: macosx 10.9.1
> URL: http://campus.hartland.edu/temp/0001-fixed-memory-leak-in-LDAPAsynConnection.cpp.patch
> Submission from: (NULL) (65.207.4.130)
>
>
> In libldapcpp, there is a memory leak in the LDAPAsynConnection class.
> ldap_initialize() allocates memory which is never freed. This memory (ld
> structure) should be freed by a call to ldap_unbind() in the class destructor
> and other places where the ld structure is replaced with a new one.
>
> I have included a patch against git master HEAD below.

Thanks for the patch, committed to master.
>
> ---
>
>>From c9b4b1a2638eec20f35c2eae31f0471cc61a21ff Mon Sep 17 00:00:00 2001
> From: "Kevin H. Patterson" <kevpatt@khptech.com>
> Date: Wed, 26 Feb 2014 13:08:24 -0500
> Subject: [PATCH] fixed memory leak in LDAPAsynConnection.cpp
>
> ---
>   contrib/ldapc++/src/LDAPAsynConnection.cpp | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/ldapc++/src/LDAPAsynConnection.cpp
> b/contrib/ldapc++/src/LDAPAsynConnection.cpp
> index 894f8ba..582d2b5 100644
> --- a/contrib/ldapc++/src/LDAPAsynConnection.cpp
> +++ b/contrib/ldapc++/src/LDAPAsynConnection.cpp
> @@ -43,7 +43,10 @@ LDAPAsynConnection::LDAPAsynConnection(const string& url, int
> port,
>       this->setConstraints(cons);
>   }
>
> -LDAPAsynConnection::~LDAPAsynConnection(){}
> +LDAPAsynConnection::~LDAPAsynConnection(){
> +	unbind();
> +	delete m_constr;
> +}
>
>   void LDAPAsynConnection::init(const string& hostname, int port){
>       DEBUG(LDAP_DEBUG_TRACE,"LDAPAsynConnection::init" << endl);
> @@ -51,6 +54,8 @@ void LDAPAsynConnection::init(const string& hostname, int
> port){
>               "   hostname:" << hostname << endl
>               << "   port:" << port << endl);
>
> +	unbind();
> +
>       m_uri.setScheme("ldap");
>       m_uri.setHost(hostname);
>       m_uri.setPort(port);
> @@ -66,6 +71,8 @@ void LDAPAsynConnection::init(const string& hostname, int
> port){
>   }
>
>   void LDAPAsynConnection::initialize(const std::string& uri){
> +	unbind();
> +
>   	m_uri.setURLString(uri);
>       int ret = ldap_initialize(&cur_session, m_uri.getURLString().c_str());
>       if ( ret != LDAP_SUCCESS ) {
> @@ -277,6 +284,7 @@ void LDAPAsynConnection::unbind(){
>
>   void LDAPAsynConnection::setConstraints(LDAPConstraints *cons){
>       DEBUG(LDAP_DEBUG_TRACE,"LDAPAsynConnection::setConstraints()" << endl);
> +	delete m_constr;
>       m_constr=cons;
>   }
>
>


-- 
   -- Howard Chu
   CTO, Symas Corp.           http://www.symas.com
   Director, Highland Sun     http://highlandsun.com/hyc/
   Chief Architect, OpenLDAP  http://www.openldap.org/project/

Comment 2 Howard Chu 2014-02-28 12:51:10 UTC
changed notes
changed state Open to Test
moved from Incoming to Contrib
Comment 3 Quanah Gibson-Mount 2014-04-01 16:46:38 UTC
changed notes
changed state Test to Release
Comment 4 OpenLDAP project 2014-10-23 07:29:23 UTC
fixed in master
fixed in RE25
fixed in RE24
Comment 5 Quanah Gibson-Mount 2014-10-23 07:29:23 UTC
changed notes
changed state Release to Closed
Comment 6 Quanah Gibson-Mount 2015-05-15 01:47:55 UTC
--On Wednesday, February 26, 2014 6:15 PM +0000 kevpatt@khptech.com wrote:

> Full_Name: Kevin H. Patterson
> Version: git master HEAD
> OS: macosx 10.9.1
> URL:
> http://campus.hartland.edu/temp/0001-fixed-memory-leak-in-LDAPAsynConnect
> ion.cpp.patch Submission from: (NULL) (65.207.4.130)
>
>
> In libldapcpp, there is a memory leak in the LDAPAsynConnection class.
> ldap_initialize() allocates memory which is never freed. This memory (ld
> structure) should be freed by a call to ldap_unbind() in the class
> destructor and other places where the ld structure is replaced with a new
> one.
>
> I have included a patch against git master HEAD below.

According to a ldap c++ user, this patch causes code to segv.  Please see 
<https://www.openldap.org/its/private.cgi/?findid=8143>

--Quanah



--

Quanah Gibson-Mount
Platform Architect
Zimbra, Inc.
--------------------
Zimbra ::  the leader in open source messaging and collaboration