]> granicus.if.org Git - php/commitdiff
Fixed segfault and memory leak in the new implementation of implode()
authorSander Roobol <sander@php.net>
Sun, 6 Oct 2002 11:28:11 +0000 (11:28 +0000)
committerSander Roobol <sander@php.net>
Sun, 6 Oct 2002 11:28:11 +0000 (11:28 +0000)
ext/standard/string.c

index a29c9b52a637914af0bfa79f974f9c8cb49ec721..eed9184d7bef7679b2047d5eccd58f446de82512 100644 (file)
@@ -825,6 +825,10 @@ PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value)
 
        numelems = zend_hash_num_elements(Z_ARRVAL_P(arr));
 
+       if(numelems == 0) {
+               RETURN_EMPTY_STRING();
+       }
+
        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
        while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), 
                                                                                 (void **) &tmp,
@@ -888,6 +892,8 @@ PHP_FUNCTION(implode)
        zval_ptr_dtor(arg1);
        if (arg2) {
                zval_ptr_dtor(arg2);
+       } else {
+               FREE_ZVAL(delim);
        }
 }
 /* }}} */