1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

ldap: Fixed DN memory leaks on failed client write

Fixed memory leaks from commit 086ad79970 as was noted in the commit
comments.
This commit is contained in:
Steve Holme 2015-01-03 17:05:50 +00:00
parent 0ea9381b7d
commit a68aa81320

View File

@ -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 * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -381,23 +381,38 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
entryIterator = ldap_next_entry(server, entryIterator), num++) { entryIterator = ldap_next_entry(server, entryIterator), num++) {
BerElement *ber = NULL; BerElement *ber = NULL;
char *attribute; /*! suspicious that this isn't 'const' */ char *attribute; /*! suspicious that this isn't 'const' */
char *dn = ldap_get_dn(server, entryIterator);
int i; int i;
/* 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: ", 4); result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"DN: ", 4);
if(result) if(result) {
ldap_memfree(dn);
goto quit; goto quit;
}
result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *) dn, 0); result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *) dn, 0);
if(result) if(result) {
ldap_memfree(dn);
goto quit; goto quit;
}
result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1); result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
if(result) if(result) {
ldap_memfree(dn);
goto quit; goto quit;
}
dlsize += strlen(dn) + 5; dlsize += strlen(dn) + 5;
ldap_memfree(dn);
}
for(attribute = ldap_first_attribute(server, entryIterator, &ber); for(attribute = ldap_first_attribute(server, entryIterator, &ber);
attribute; attribute;
attribute = ldap_next_attribute(server, entryIterator, ber)) { attribute = ldap_next_attribute(server, entryIterator, ber)) {
@ -432,7 +447,6 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
if(error) { if(error) {
ldap_value_free_len(vals); ldap_value_free_len(vals);
ldap_memfree(attribute); ldap_memfree(attribute);
ldap_memfree(dn);
if(ber) if(ber)
ber_free(ber, 0); ber_free(ber, 0);
result = error; result = error;
@ -470,7 +484,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
Curl_pgrsSetDownloadCounter(data, dlsize); Curl_pgrsSetDownloadCounter(data, dlsize);
ldap_memfree(attribute); ldap_memfree(attribute);
} }
ldap_memfree(dn);
if(ber) if(ber)
ber_free(ber, 0); ber_free(ber, 0);
} }