r10213: fixed a memory leak in the ldap client and server code spotted by Karl
authorAndrew Tridgell <tridge@samba.org>
Tue, 13 Sep 2005 22:05:45 +0000 (22:05 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:38:09 +0000 (13:38 -0500)
Melcher. ldap_encode() now takes a memory context to use for the data
blob

source/ldap_server/ldap_server.c
source/libcli/cldap/cldap.c
source/libcli/ldap/ldap.c
source/libcli/ldap/ldap_client.c

index 4320a0ad5e778eec485baac7cf513a77b40645da..92adc8a890e783651336347471a10b8695158aa7 100644 (file)
@@ -87,12 +87,14 @@ static void ldapsrv_process_message(struct ldapsrv_connection *conn,
                DATA_BLOB b;
 
                msg = call->replies->msg;
-               if (!ldap_encode(msg, &b)) {
+               if (!ldap_encode(msg, &b, call)) {
                        DEBUG(0,("Failed to encode ldap reply of type %d\n", msg->type));
                        goto failed;
                }
 
                status = data_blob_append(call, &blob, b.data, b.length);
+               data_blob_free(&b);
+
                if (!NT_STATUS_IS_OK(status)) goto failed;
 
                DLIST_REMOVE(call->replies, call->replies);
index 4ffa40d1349d2e900ec35f9acd609f7f8fb64476..07744553c805358f4642bf58546acf49013eea9a 100644 (file)
@@ -337,12 +337,11 @@ struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
                goto failed;
        }
 
-       if (!ldap_encode(msg, &req->encoded)) {
+       if (!ldap_encode(msg, &req->encoded, req)) {
                DEBUG(0,("Failed to encode cldap message to %s:%d\n",
                         req->dest_addr, req->dest_port));
                goto failed;
        }
-       talloc_steal(req, req->encoded.data);
 
        DLIST_ADD_END(cldap->send_queue, req, struct cldap_request *);
 
@@ -389,13 +388,12 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
                msg->type = LDAP_TAG_SearchResultEntry;
                msg->r.SearchResultEntry = *io->response;
 
-               if (!ldap_encode(msg, &blob1)) {
+               if (!ldap_encode(msg, &blob1, req)) {
                        DEBUG(0,("Failed to encode cldap message to %s:%d\n",
                                 req->dest_addr, req->dest_port));
                        status = NT_STATUS_INVALID_PARAMETER;
                        goto failed;
                }
-               talloc_steal(req, blob1.data);
        } else {
                blob1 = data_blob(NULL, 0);
        }
@@ -403,13 +401,12 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
        msg->type = LDAP_TAG_SearchResultDone;
        msg->r.SearchResultDone = *io->result;
 
-       if (!ldap_encode(msg, &blob2)) {
+       if (!ldap_encode(msg, &blob2, req)) {
                DEBUG(0,("Failed to encode cldap message to %s:%d\n",
                         req->dest_addr, req->dest_port));
                status = NT_STATUS_INVALID_PARAMETER;
                goto failed;
        }
-       talloc_steal(req, blob2.data);
 
        req->encoded = data_blob_talloc(req, NULL, blob1.length + blob2.length);
        if (req->encoded.data == NULL) goto failed;
index f7f6feea383ad67df138770402f322b1d4a7e9a4..815d543038285c41af5932ebbb231b46e0b9ae1e 100644 (file)
@@ -189,7 +189,7 @@ static void ldap_encode_response(struct asn1_data *data, struct ldap_Result *res
        }
 }
 
-BOOL ldap_encode(struct ldap_message *msg, DATA_BLOB *result)
+BOOL ldap_encode(struct ldap_message *msg, DATA_BLOB *result, TALLOC_CTX *mem_ctx)
 {
        struct asn1_data data;
        int i, j;
@@ -462,7 +462,7 @@ BOOL ldap_encode(struct ldap_message *msg, DATA_BLOB *result)
                return False;
        }
 
-       *result = data_blob(data.data, data.length);
+       *result = data_blob_talloc(mem_ctx, data.data, data.length);
        asn1_free(&data);
        return True;
 }
index 97b75602aaaecfd80048d11ea99ba9b5bdc57b40..800e523eb40327d55bc33838cba96049608f4c7c 100644 (file)
@@ -497,7 +497,7 @@ struct ldap_request *ldap_request_send(struct ldap_connection *conn,
 
        msg->messageid = req->messageid;
 
-       if (!ldap_encode(msg, &req->data)) {
+       if (!ldap_encode(msg, &req->data, req)) {
                goto failed;            
        }