Module: kamailio
Branch: master
Commit: 87edc25fd458be80ed5cfec21fbe2940a8f9c17f
URL:
https://github.com/kamailio/kamailio/commit/87edc25fd458be80ed5cfec21fbe294…
Author: Vitaliy Aleksandrov <vitalik.voip(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-04-18T14:27:12+02:00
ldap: fix memory leak that happens after calling ldap_result_next()
- GH #1071
---
Modified: src/modules/ldap/ldap_api_fn.c
---
Diff:
https://github.com/kamailio/kamailio/commit/87edc25fd458be80ed5cfec21fbe294…
Patch:
https://github.com/kamailio/kamailio/commit/87edc25fd458be80ed5cfec21fbe294…
---
diff --git a/src/modules/ldap/ldap_api_fn.c b/src/modules/ldap/ldap_api_fn.c
index 05b4119..d95d1cc 100644
--- a/src/modules/ldap/ldap_api_fn.c
+++ b/src/modules/ldap/ldap_api_fn.c
@@ -39,6 +39,7 @@
#include "ld_session.h"
static LDAP* last_ldap_handle = NULL;
+static LDAPMessage* last_ldap_result_holder = NULL;
static LDAPMessage* last_ldap_result = NULL;
int get_connected_ldap_session(
@@ -111,9 +112,10 @@ int get_connected_ldap_session(char* _lds_name, struct ld_session**
_lds)
}
else
{
- if (last_ldap_result != NULL)
+ if (last_ldap_result_holder != NULL)
{
- ldap_msgfree(last_ldap_result);
+ ldap_msgfree(last_ldap_result_holder);
+ last_ldap_result_holder = NULL;
last_ldap_result = NULL;
}
ldap_disconnect(_lds_name);
@@ -412,9 +414,10 @@ int lds_search(
/*
* free last_ldap_result
*/
- if (last_ldap_result != NULL) {
- ldap_msgfree(last_ldap_result);
- last_ldap_result = NULL;
+ if (last_ldap_result_holder != NULL) {
+ ldap_msgfree(last_ldap_result_holder);
+ last_ldap_result_holder = NULL;
+ last_ldap_result = NULL;
}
@@ -445,7 +448,7 @@ int lds_search(
NULL,
&lds->client_search_timeout,
0,
- &last_ldap_result);
+ &last_ldap_result_holder);
#ifdef LDAP_PERF
gettimeofday(&after_search, NULL);
@@ -458,10 +461,10 @@ int lds_search(
if (*_ld_error != LDAP_SUCCESS)
{
- if (last_ldap_result != NULL)
+ if (last_ldap_result_holder != NULL)
{
- ldap_msgfree(last_ldap_result);
- last_ldap_result = NULL;
+ ldap_msgfree(last_ldap_result_holder);
+ last_ldap_result_holder = NULL;
}
if (LDAP_API_ERROR(*_ld_error))
@@ -476,13 +479,15 @@ int lds_search(
}
last_ldap_handle = lds->handle;
- *_ld_result_count = ldap_count_entries(lds->handle, last_ldap_result);
+ *_ld_result_count = ldap_count_entries(lds->handle, last_ldap_result_holder);
if (*_ld_result_count < 0)
{
LM_DBG("[%s]: ldap_count_entries failed\n", _lds_name);
return -1;
}
+ last_ldap_result = last_ldap_result_holder;
+
return 0;
}