* fix fatal erealloc error
authorMichael Wallner <mike@php.net>
Wed, 16 Feb 2005 16:58:51 +0000 (16:58 +0000)
committerMichael Wallner <mike@php.net>
Wed, 16 Feb 2005 16:58:51 +0000 (16:58 +0000)
http_api.c

index 238dd5a1a2b565eb39f0369a87cf434e166268f2..b099b5aca729397a7358155d84896e870ef836a8 100644 (file)
@@ -1112,39 +1112,38 @@ PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len,
 /* }}} */
 
 /* {{{ STATUS http_start_ob_handler(php_output_handler_func_t, char *, uint, zend_bool) */
-PHP_HTTP_API STATUS _http_start_ob_handler(php_output_handler_func_t handler_func, 
+PHP_HTTP_API STATUS _http_start_ob_handler(php_output_handler_func_t handler_func,
        char *handler_name, uint chunk_size, zend_bool erase TSRMLS_DC)
 {
        php_ob_buffer **stack;
        int count, i;
-       STATUS result;
-       
-       count = OG(ob_nesting_level);
-       stack = emalloc(sizeof(php_ob_buffer *) * count);
 
-       if (count > 1) {
-               zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, 
-                       (int (*)(void *elem, void *)) http_ob_stack_get, stack);
-       }
-       
-       if (count > 0) {
-               http_ob_stack_get(&OG(active_ob_buffer), stack);
-       }
-       
-       while (OG(ob_nesting_level)) {
-               php_end_ob_buffer(0, 0 TSRMLS_CC);
+       if (count = OG(ob_nesting_level)) {
+               stack = ecalloc(sizeof(php_ob_buffer), count);
+
+               if (count > 1) {
+                       zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP,
+                               (int (*)(void *elem, void *)) http_ob_stack_get, stack);
+               }
+
+               if (count > 0) {
+                       http_ob_stack_get(&OG(active_ob_buffer), stack);
+               }
+
+               while (OG(ob_nesting_level)) {
+                       php_end_ob_buffer(0, 0 TSRMLS_CC);
+               }
        }
        
-       php_ob_set_internal_handler(handler_func, 0, handler_name, 0 TSRMLS_CC);
-       result = php_start_ob_buffer_named(handler_name, chunk_size, erase TSRMLS_CC);
-       
+       php_ob_set_internal_handler(handler_func, chunk_size, handler_name, erase TSRMLS_CC);
+
        for (i = 0; i < count; i++) {
                php_ob_buffer *s = stack[i];
                php_start_ob_buffer_named(s->handler_name, s->chunk_size, s->erase TSRMLS_CC);
                php_body_write(s->buffer, s->text_length TSRMLS_CC);
        }
-       
-       return result;
+
+       return SUCCESS;
 }
 /* }}} */