summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2015-01-03 17:05:50 +0000
committerSteve Holme <steve_holme@hotmail.com>2015-01-03 18:46:28 +0000
commita68aa81320aca4d376fe2a43ee8c76a6eb6b8f01 (patch)
treea20b8c0283dffe313cfe810e28f1ea36391f4229
parent0ea9381b7da0abd016443f50497a521cda343554 (diff)
downloadgnurl-a68aa81320aca4d376fe2a43ee8c76a6eb6b8f01.tar.gz
gnurl-a68aa81320aca4d376fe2a43ee8c76a6eb6b8f01.tar.bz2
gnurl-a68aa81320aca4d376fe2a43ee8c76a6eb6b8f01.zip
ldap: Fixed DN memory leaks on failed client write
Fixed memory leaks from commit 086ad79970 as was noted in the commit comments.
-rw-r--r--lib/ldap.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/lib/ldap.c b/lib/ldap.c
index 96521bf21..80c2ddb09 100644
--- a/lib/ldap.c
+++ b/lib/ldap.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -381,22 +381,37 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
entryIterator = ldap_next_entry(server, entryIterator), num++) {
BerElement *ber = NULL;
char *attribute; /*! suspicious that this isn't 'const' */
- char *dn = ldap_get_dn(server, entryIterator);
int i;
- result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"DN: ", 4);
- if(result)
- goto quit;
+ /* Get the DN and write it to the client */
+ {
+ char *dn = ldap_get_dn(server, entryIterator);
- result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)dn, 0);
- if(result)
- goto quit;
+ result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"DN: ", 4);
+ if(result) {
+ ldap_memfree(dn);
- result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
- if(result)
- goto quit;
+ goto quit;
+ }
- dlsize += strlen(dn)+5;
+ result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *) dn, 0);
+ if(result) {
+ ldap_memfree(dn);
+
+ goto quit;
+ }
+
+ result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
+ if(result) {
+ ldap_memfree(dn);
+
+ goto quit;
+ }
+
+ dlsize += strlen(dn) + 5;
+
+ ldap_memfree(dn);
+ }
for(attribute = ldap_first_attribute(server, entryIterator, &ber);
attribute;
@@ -432,7 +447,6 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
if(error) {
ldap_value_free_len(vals);
ldap_memfree(attribute);
- ldap_memfree(dn);
if(ber)
ber_free(ber, 0);
result = error;
@@ -470,7 +484,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
Curl_pgrsSetDownloadCounter(data, dlsize);
ldap_memfree(attribute);
}
- ldap_memfree(dn);
+
if(ber)
ber_free(ber, 0);
}