From: Michael Wallner Date: Mon, 17 Oct 2005 14:19:20 +0000 (+0000) Subject: - fix remaining issues; there's still a 1-byte memleak I could not find yet X-Git-Tag: RELEASE_0_16_0~9 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3f97cec39ebeae3bdafc082d310e878f995b04e8;p=m6w6%2Fext-http - fix remaining issues; there's still a 1-byte memleak I could not find yet --- diff --git a/http_encoding_api.c b/http_encoding_api.c index 87a4b17..00ea702 100644 --- a/http_encoding_api.c +++ b/http_encoding_api.c @@ -151,13 +151,13 @@ inline void http_init_uncompress_buffer(size_t data_len, char **buf_ptr, size_t *buf_ptr = emalloc(*buf_len + 1); } else { size_t new_len = *buf_len << 2; - char *new_ptr = erealloc(*buf_ptr, new_len + 1); + char *new_ptr = erealloc_recoverable(*buf_ptr, new_len + 1); if (new_ptr) { *buf_ptr = new_ptr; *buf_len = new_len; } else { - *iteration = INT_MAX; + *iteration = INT_MAX-1; /* avoid integer overflow on increment op */ } } } @@ -602,6 +602,8 @@ PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML add_next_index_stringl(&zsupported, "gzip", lenof("gzip"), 1); add_next_index_stringl(&zsupported, "deflate", lenof("deflate"), 1); + HTTP_G(send).gzip_encoding = 0; + if (selected = http_negotiate_encoding(&zsupported)) { STATUS hs = FAILURE; char *encoding = NULL; @@ -619,8 +621,6 @@ PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML } if (SUCCESS == hs) { http_send_header_string("Vary: Accept-Encoding"); - } else { - HTTP_G(send).gzip_encoding = 0; } } @@ -629,7 +629,7 @@ PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML } zval_dtor(&zsupported); - return 1; + return HTTP_G(send).gzip_encoding; #endif } } diff --git a/http_send_api.c b/http_send_api.c index bfdcaab..328c713 100644 --- a/http_send_api.c +++ b/http_send_api.c @@ -100,7 +100,7 @@ static inline void _http_send_response_data_plain(void **buffer, const char *dat http_encoding_stream *s = *((http_encoding_stream **) buffer); http_encoding_stream_update(s, data, data_len, &encoded, &encoded_len); - phpstr_chunked_output(&s->storage, data, data_len, HTTP_G(send).buffer_size, _http_flush TSRMLS_CC); + phpstr_chunked_output(&s->storage, encoded, encoded_len, HTTP_G(send).buffer_size, _http_flush TSRMLS_CC); efree(encoded); #else http_error(HE_ERROR, HTTP_E_RESPONSE, "Attempt to send GZIP response despite being able to do so; please report this bug"); @@ -167,18 +167,19 @@ static inline void _http_send_response_finish(void **buffer TSRMLS_DC) if (HTTP_G(send).gzip_encoding) { #ifdef HTTP_HAVE_ZLIB char *encoded = NULL; - size_t encoded_len; + size_t encoded_len = 0; http_encoding_stream *s = *((http_encoding_stream **) buffer); http_encoding_stream_finish(s, &encoded, &encoded_len); - buffer = &s->storage; - phpstr_chunked_output((phpstr **) buffer, encoded, encoded_len, HTTP_G(send).buffer_size, _http_flush TSRMLS_CC); + phpstr_chunked_output(&s->storage, encoded, encoded_len, 0, _http_flush TSRMLS_CC); STR_FREE(encoded); + efree(s); #else http_error(HE_ERROR, HTTP_E_RESPONSE, "Attempt to send GZIP response despite being able to do so; please report this bug"); #endif + } else { + phpstr_chunked_output((phpstr **) buffer, NULL, 0, 0, _http_flush TSRMLS_CC); } - phpstr_chunked_output((phpstr **) buffer, NULL, 0, 0, _http_flush TSRMLS_CC); } /* }}} */ diff --git a/phpstr/phpstr.c b/phpstr/phpstr.c index f9ae25c..45c9e26 100644 --- a/phpstr/phpstr.c +++ b/phpstr/phpstr.c @@ -262,7 +262,7 @@ PHPSTR_API size_t phpstr_chunk_buffer(phpstr **s, const char *data, size_t data_ if (!chunk_size) { phpstr_data(storage, chunk, &chunk_size); - phpstr_free(&storage); + phpstr_free(s); return chunk_size; } @@ -288,6 +288,8 @@ PHPSTR_API void phpstr_chunked_output(phpstr **s, const char *data, size_t data_ data = NULL; data_len = 0; if (!chunk_len) { + /* we already got the last chunk, + and freed all resources */ break; } } diff --git a/tests/send_data_008.phpt b/tests/send_data_008.phpt index eb2a9e0..cb0fc6d 100644 --- a/tests/send_data_008.phpt +++ b/tests/send_data_008.phpt @@ -7,7 +7,7 @@ checkcgi(); ?> --FILE-- --EXPECTF--