[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: (ITS#7806) memory leak in contrib/ldapc++/LDAPAsynConnection.cpp



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/