]> granicus.if.org Git - php/commitdiff
use HashPosition to prevent race condition in multithreaded env
authorAntony Dovgal <tony2001@php.net>
Thu, 2 Oct 2008 08:46:04 +0000 (08:46 +0000)
committerAntony Dovgal <tony2001@php.net>
Thu, 2 Oct 2008 08:46:04 +0000 (08:46 +0000)
ext/standard/info.c
ext/standard/streamsfuncs.c

index 667d8a5aef42947af41a4846d6563da383a7e200..24ea0fe6ab7961f58b1736a0b5b051baf46953b7 100644 (file)
@@ -139,14 +139,16 @@ static void php_info_print_stream_hash(const char *name, HashTable *ht TSRMLS_DC
        
        if (ht) {
                if (zend_hash_num_elements(ht)) {
+                       HashPosition pos;
+
                        if (!sapi_module.phpinfo_as_text) {
                                php_info_printf("<tr class=\"v\"><td>Registered %s</td><td>", name);
                        } else {
                                php_info_printf("\nRegistered %s => ", name);
                        }
                        
-                       zend_hash_internal_pointer_reset(ht);
-                       type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, NULL);
+                       zend_hash_internal_pointer_reset_ex(ht, &pos);
+                       type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, &pos);
                        do {
                                switch (type) {
                                        case IS_STRING:
@@ -157,8 +159,8 @@ static void php_info_print_stream_hash(const char *name, HashTable *ht TSRMLS_DC
                                                break;
                                }
                                
-                               zend_hash_move_forward(ht);
-                               type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, NULL);
+                               zend_hash_move_forward_ex(ht, &pos);
+                               type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, &pos);
                                
                                if (type == IS_STRING || type == IS_UNICODE) {
                                        php_info_print(", ");
index 71857dffcf8e8b39727cb230190f8ef86c62e642..5fcae2c19d54f091a6386957df45c160f417affc 100644 (file)
@@ -573,13 +573,14 @@ PHP_FUNCTION(stream_get_transports)
        }
 
        if ((stream_xport_hash = php_stream_xport_get_hash())) {
+               HashPosition pos;
                array_init(return_value);
-               zend_hash_internal_pointer_reset(stream_xport_hash);
+               zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos);
                while (zend_hash_get_current_key_ex(stream_xport_hash,
                                        &stream_xport, &stream_xport_len,
-                                       &num_key, 0, NULL) == HASH_KEY_IS_STRING) {
+                                       &num_key, 0, &pos) == HASH_KEY_IS_STRING) {
                        add_next_index_rt_stringl(return_value, stream_xport.s, stream_xport_len - 1, ZSTR_DUPLICATE);
-                       zend_hash_move_forward(stream_xport_hash);
+                       zend_hash_move_forward_ex(stream_xport_hash, &pos);
                }
        } else {
                RETURN_FALSE;
@@ -601,10 +602,11 @@ PHP_FUNCTION(stream_get_wrappers)
        }
 
        if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
+               HashPosition pos;
                array_init(return_value);
-               for(zend_hash_internal_pointer_reset(url_stream_wrappers_hash);
-                       (key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, &num_key, 0, NULL)) != HASH_KEY_NON_EXISTANT;
-                       zend_hash_move_forward(url_stream_wrappers_hash)) {
+               for(zend_hash_internal_pointer_reset_ex(url_stream_wrappers_hash, &pos);
+                       (key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTANT;
+                       zend_hash_move_forward_ex(url_stream_wrappers_hash, &pos)) {
                                if (key_flags == HASH_KEY_IS_STRING) {
                                        add_next_index_rt_stringl(return_value, stream_protocol.s, stream_protocol_len - 1, ZSTR_DUPLICATE);
                                }