Author: gsim Date: Fri Oct 10 12:36:59 2014 New Revision: 1630778 URL: http://svn.apache.org/r1630778 Log: PROTON-611: Don't allocate frame_max bytes immediately, grow by factors of 2 until you get to the max - else a large frame size can blow away 4Gb of memory!
Modified: qpid/proton/branches/examples/proton-c/src/ssl/openssl.c qpid/proton/branches/examples/proton-c/src/transport/transport.c Modified: qpid/proton/branches/examples/proton-c/src/ssl/openssl.c URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-c/src/ssl/openssl.c?rev=1630778&r1=1630777&r2=1630778&view=diff ============================================================================== --- qpid/proton/branches/examples/proton-c/src/ssl/openssl.c (original) +++ qpid/proton/branches/examples/proton-c/src/ssl/openssl.c Fri Oct 10 12:36:59 2014 @@ -908,14 +908,13 @@ static ssize_t process_input_ssl( pn_io_ if (!max_frame) max_frame = ssl->in_size * 2; // no limit if (ssl->in_size < max_frame) { // no max frame limit - grow it. - char *newbuf = (char *)malloc( max_frame ); + size_t newsize = pn_min(max_frame, ssl->in_size * 2); + char *newbuf = (char *)realloc( ssl->inbuf, newsize ); if (newbuf) { - ssl->in_size = max_frame; - memmove( newbuf, ssl->inbuf, ssl->in_count ); - free( ssl->inbuf ); + ssl->in_size = newsize; ssl->inbuf = newbuf; + work_pending = true; // can we get more input? } - work_pending = true; // can we get more input? } else { // can't gather any more input, but app needs more? // This is a bug - since SSL can buffer up to max-frame, Modified: qpid/proton/branches/examples/proton-c/src/transport/transport.c URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-c/src/transport/transport.c?rev=1630778&r1=1630777&r2=1630778&view=diff ============================================================================== --- qpid/proton/branches/examples/proton-c/src/transport/transport.c (original) +++ qpid/proton/branches/examples/proton-c/src/transport/transport.c Fri Oct 10 12:36:59 2014 @@ -1740,20 +1740,18 @@ static ssize_t transport_produce(pn_tran pn_io_layer_t *io_layer = transport->io_layers; ssize_t space = transport->output_size - transport->output_pending; - if (space == 0) { // can we expand the buffer? + if (space <= 0) { // can we expand the buffer? int more = 0; if (!transport->remote_max_frame) // no limit, so double it more = transport->output_size; else if (transport->remote_max_frame > transport->output_size) - more = transport->remote_max_frame - transport->output_size; + more = pn_min(transport->output_size, transport->remote_max_frame - transport->output_size); if (more) { - char *newbuf = (char *)malloc( transport->output_size + more ); + char *newbuf = (char *)realloc( transport->output_buf, transport->output_size + more ); if (newbuf) { - memmove( newbuf, transport->output_buf, transport->output_pending ); - free( transport->output_buf ); transport->output_buf = newbuf; transport->output_size += more; - space = more; + space += more; } } } @@ -1955,22 +1953,20 @@ ssize_t pn_transport_capacity(pn_transpo //if (pn_error_code(transport->error)) return pn_error_code(transport->error); ssize_t capacity = transport->input_size - transport->input_pending; - if (!capacity) { + if ( capacity<=0 ) { // can we expand the size of the input buffer? int more = 0; if (!transport->local_max_frame) { // no limit (ha!) more = transport->input_size; } else if (transport->local_max_frame > transport->input_size) { - more = transport->local_max_frame - transport->input_size; + more = pn_min(transport->input_size, transport->local_max_frame - transport->input_size); } if (more) { - char *newbuf = (char *) malloc( transport->input_size + more ); + char *newbuf = (char *) realloc( transport->input_buf, transport->input_size + more ); if (newbuf) { - memmove( newbuf, transport->input_buf, transport->input_pending ); - free( transport->input_buf ); transport->input_buf = newbuf; transport->input_size += more; - capacity = more; + capacity += more; } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org