release 2.6.0
[m6w6/ext-http] / src / php_http_buffer.c
index e24a4e18baa2e4d7e7a6c8cbdbf7d7c7967fc31b..64e559a5907f0c8a051d350d3511f8863fa9a683 100644 (file)
@@ -10,7 +10,7 @@
     +--------------------------------------------------------------------+
 */
 
-#include <php.h>
+#include "php.h"
 #include "php_http_buffer.h"
 
 PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(php_http_buffer_t *buf, size_t chunk_size, int flags)
@@ -32,9 +32,13 @@ PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(php_http_buffer_t
 
 PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(php_http_buffer_t *buf, const char *string, size_t length)
 {
+       int free_buf = !!buf;
+
        if ((buf = php_http_buffer_init(buf))) {
                if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, string, length)) {
-                       pefree(buf, buf->pmem);
+                       if (free_buf) {
+                               pefree(buf, buf->pmem);
+                       }
                        buf = NULL;
                }
        }