Skip to content

Commit

Permalink
Memory leak, missing ldap_msgfree on SASL binds.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmocm committed Jan 7, 2017
1 parent f78fb44 commit 2747b1c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion LDAPCnx.cc
Expand Up @@ -200,7 +200,7 @@ void LDAPCnx::Event(uv_poll_t* handle, int status, int events) {
int msgid = ldap_msgid(message);

if(err == LDAP_SASL_BIND_IN_PROGRESS) {
err = ld->SASLBindNext(message);
err = ld->SASLBindNext(&message);
if(err != LDAP_SUCCESS) {
errparam = Nan::Error(ldap_err2string(err));
}
Expand Down
2 changes: 1 addition & 1 deletion LDAPCnx.h
Expand Up @@ -39,7 +39,7 @@ class LDAPCnx : public Nan::ObjectWrap {
static void CheckTLS (const Nan::FunctionCallbackInfo<v8::Value>& info);
static int isBinary (char * attrname);

int SASLBindNext(LDAPMessage* result);
int SASLBindNext(LDAPMessage** result);
const char* sasl_mechanism;

ldap_conncb * ldap_callback;
Expand Down
13 changes: 7 additions & 6 deletions LDAPSASL.cc
Expand Up @@ -38,25 +38,26 @@ void LDAPCnx::SASLBind(const Nan::FunctionCallbackInfo<Value>& info) {
info.GetReturnValue().Set(msgid);
}

int LDAPCnx::SASLBindNext(LDAPMessage* message) {
int LDAPCnx::SASLBindNext(LDAPMessage** message) {
LDAPControl** sctrlsp = NULL;
int res;
int msgid;
do {
while(true) {
res = ldap_sasl_interactive_bind(ld, NULL, NULL,
sctrlsp, NULL, LDAP_SASL_QUIET, NULL, NULL,
message, &sasl_mechanism, &msgid);
*message, &sasl_mechanism, &msgid);

if(res != LDAP_SASL_BIND_IN_PROGRESS) {
break;
}

if(ldap_result(ld, msgid, LDAP_MSG_ALL, NULL, &message) != LDAP_SUCCESS) {
ldap_msgfree(*message);

if(ldap_result(ld, msgid, LDAP_MSG_ALL, NULL, message) != LDAP_SUCCESS) {
ldap_get_option(ld, LDAP_OPT_RESULT_CODE, &res);
break;
}

} while(res == LDAP_SASL_BIND_IN_PROGRESS);
}

return res;
}
Expand Down
2 changes: 1 addition & 1 deletion LDAPXSASL.cc
Expand Up @@ -4,6 +4,6 @@ void LDAPCnx::SASLBind(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Nan::ThrowError("LDAP module was not built with SASL support");
}

int LDAPCnx::SASLBindNext(LDAPMessage* result) {
int LDAPCnx::SASLBindNext(LDAPMessage** result) {
return -1;
}

0 comments on commit 2747b1c

Please sign in to comment.