Make current_in_pdu in pipes_struct allocated
authorVolker Lendecke <vl@samba.org>
Sat, 7 Feb 2009 15:24:08 +0000 (16:24 +0100)
committerVolker Lendecke <vl@samba.org>
Sat, 7 Feb 2009 18:25:34 +0000 (19:25 +0100)
This makes an open pipe about 4K cheaper

source3/include/ntdomain.h
source3/rpc_server/srv_pipe_hnd.c

index 2d6a35839165fc07026763cf62ff194179869ee4..7ac4dcefd17b18bcfdbab2225e91ed92e5347a5a 100644 (file)
@@ -89,7 +89,7 @@ typedef struct _input_data {
         * pdu is seen, then the data is copied into the in_data
         * structure. The maximum size of this is 0x1630 (RPC_MAX_PDU_FRAG_LEN).
         */
-       unsigned char current_in_pdu[RPC_MAX_PDU_FRAG_LEN];
+       uint8_t *current_in_pdu;
 
        /*
         * The amount of data needed to complete the in_pdu.
index 4cbe8d67a352161fdbb74ce09a1b72db850a963c..56c4a317e559b70383fd8bb3089bb861ba0374f0 100644 (file)
@@ -192,6 +192,15 @@ static ssize_t fill_rpc_header(pipes_struct *p, char *data, size_t data_to_copy)
                        (unsigned int)data_to_copy, (unsigned int)len_needed_to_complete_hdr,
                        (unsigned int)p->in_data.pdu_received_len ));
 
+       if (p->in_data.current_in_pdu == NULL) {
+               p->in_data.current_in_pdu = talloc_array(p, uint8_t,
+                                                        RPC_HEADER_LEN);
+       }
+       if (p->in_data.current_in_pdu == NULL) {
+               DEBUG(0, ("talloc failed\n"));
+               return -1;
+       }
+
        memcpy((char *)&p->in_data.current_in_pdu[p->in_data.pdu_received_len], data, len_needed_to_complete_hdr);
        p->in_data.pdu_received_len += len_needed_to_complete_hdr;
 
@@ -312,6 +321,14 @@ static ssize_t unmarshall_rpc_header(pipes_struct *p)
 
        prs_mem_free(&rpc_in);
 
+       p->in_data.current_in_pdu = TALLOC_REALLOC_ARRAY(
+               p, p->in_data.current_in_pdu, uint8_t, p->hdr.frag_len);
+       if (p->in_data.current_in_pdu == NULL) {
+               DEBUG(0, ("talloc failed\n"));
+               set_incoming_fault(p);
+               return -1;
+       }
+
        return 0; /* No extra data processed. */
 }
 
@@ -635,6 +652,7 @@ static void process_complete_pdu(pipes_struct *p)
                /*
                 * Reset the lengths. We're ready for a new pdu.
                 */
+               TALLOC_FREE(p->in_data.current_in_pdu);
                p->in_data.pdu_needed_len = 0;
                p->in_data.pdu_received_len = 0;
        }