Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

m_ldapoper Fix memory leak

See 1813369 for details
  • Loading branch information...
commit c2549b040243e0fcaac0ec2e6d461980cda7f5f4 1 parent 4e9cfa5
@attilamolnar attilamolnar authored
Showing with 27 additions and 1 deletion.
  1. +27 −1 src/modules/extra/m_ldapoper.cpp
View
28 src/modules/extra/m_ldapoper.cpp
@@ -35,6 +35,31 @@
/* $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 @@ class ModuleLDAPAuth : public Module
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);
Please sign in to comment.
Something went wrong with that request. Please try again.