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)
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/
changed notes changed state Open to Test moved from Incoming to Contrib
changed notes changed state Test to Release
fixed in master fixed in RE25 fixed in RE24
changed notes changed state Release to Closed
--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