]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
m_ldapoper Fix memory leak
authorattilamolnar <attilamolnar@hush.com>
Mon, 11 Mar 2013 18:53:54 +0000 (19:53 +0100)
committerattilamolnar <attilamolnar@hush.com>
Fri, 29 Mar 2013 00:09:34 +0000 (01:09 +0100)
See 1813369adecc1efc9812e90c40c21dc32e4965c9 for details

src/modules/extra/m_ldapoper.cpp

index e9e25630c30ffc280cbe0d57f3164cc51706f092..69131f7bc4005807fb4120d388d4b98e6a42f580 100644 (file)
 /* $ModDesc: Adds the ability to authenticate opers via LDAP */
 /* $LinkerFlags: -lldap */
 
+struct RAIILDAPString
+{
+       char *str;
+
+       RAIILDAPString(char *Str)
+               : str(Str)
+       {
+       }
+
+       ~RAIILDAPString()
+       {
+               ldap_memfree(str);
+       }
+
+       operator char*()
+       {
+               return str;
+       }
+
+       operator std::string()
+       {
+               return str;
+       }
+};
+
 class ModuleLDAPAuth : public Module
 {
        std::string base;
@@ -165,7 +190,8 @@ public:
                authpass = strdup(opassword.c_str());
                cred.bv_val = authpass;
                cred.bv_len = opassword.length();
-               if ((res = ldap_sasl_bind_s(conn, ldap_get_dn(conn, entry), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL)) == LDAP_SUCCESS)
+               RAIILDAPString DN(ldap_get_dn(conn, entry));
+               if ((res = ldap_sasl_bind_s(conn, DN, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL)) == LDAP_SUCCESS)
                {
                        free(authpass);
                        ldap_msgfree(msg);