- sanitize stream filter
[m6w6/ext-http] / phpstr / phpstr.c
index 3e8e311ee464246e24ce0e9383e79039b46cf488..5a153dbcbc00b3bb6b56fae42ed69cd2cfd0918a 100644 (file)
@@ -4,7 +4,7 @@
 #include "php.h"
 #include "phpstr.h"
 
-PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, zend_bool pre_alloc)
+PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, int pre_alloc)
 {
        if (!buf) {
                buf = emalloc(sizeof(phpstr));
@@ -229,6 +229,12 @@ PHPSTR_API int phpstr_cmp(phpstr *left, phpstr *right)
        }
 }
 
+PHPSTR_API void phpstr_reset(phpstr *buf)
+{
+       buf->free += buf->used;
+       buf->used = 0;
+}
+
 PHPSTR_API void phpstr_dtor(phpstr *buf)
 {
        STR_SET(buf->data, NULL);
@@ -262,7 +268,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;
        }
        
@@ -284,10 +290,16 @@ PHPSTR_API void phpstr_chunked_output(phpstr **s, const char *data, size_t data_
        
        while (got = phpstr_chunk_buffer(s, data, data_len, &chunk, chunk_len)) {
                passthru(chunk, got TSRMLS_CC);
-               efree(chunk);
+               if (!chunk_len) {
+                       /*      we already got the last chunk,
+                               and freed all resources */
+                       break;
+               }
                data = NULL;
                data_len = 0;
+               STR_SET(chunk, NULL);
        }
+       STR_FREE(chunk);
 }
 
 /*