- fix remaining issues; there's still a 1-byte memleak I could not find yet
authorMichael Wallner <mike@php.net>
Mon, 17 Oct 2005 14:19:20 +0000 (14:19 +0000)
committerMichael Wallner <mike@php.net>
Mon, 17 Oct 2005 14:19:20 +0000 (14:19 +0000)
http_encoding_api.c
http_send_api.c
phpstr/phpstr.c
tests/send_data_008.phpt

index 87a4b175ceae4225d881a5acf654a2b0070a47a1..00ea70283cf385dc44d5a72a15ca1fed8cb14987 100644 (file)
@@ -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
                }
        }
index bfdcaab97f0d732d8652bfa56b7deb677e8bb6a1..328c713cbccacc1b5cea949ce7613f0a5a094585 100644 (file)
@@ -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);
 }
 /* }}} */
 
index f9ae25c41440d8817bcd01028c69999993b6cbc2..45c9e2632bb6293a10765d59f6dd941e598b4335 100644 (file)
@@ -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;
                }
        }
index eb2a9e072fc039e61b8d2d10b1285ef5233f3054..cb0fc6df094c61cc7b5c7f2480456bb963406005 100644 (file)
@@ -7,7 +7,7 @@ checkcgi();
 ?>
 --FILE--
 <?php
-http_throttle(0.01, 20);
+http_throttle(0.01, 1);
 http_send_data('00000000000000000000');
 ?>
 --EXPECTF--