Skip to content

Commit 9f6edf8

Browse files
author
Michael Maclean
committed
Iterate over hosts hash table in a safer way
1 parent a308b81 commit 9f6edf8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

redis_array_impl.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern zend_class_entry *redis_ce;
3232
RedisArray*
3333
ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b_lazy_connect TSRMLS_DC)
3434
{
35-
int i, host_len, id;
35+
int i = 0, host_len, id;
3636
int count = zend_hash_num_elements(hosts);
3737
char *host, *p;
3838
short port;
@@ -43,10 +43,10 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b
4343
ZVAL_STRING(&z_cons, "__construct", 0);
4444

4545
/* init connections */
46-
for(i = 0; i < count; ++i) {
47-
if(FAILURE == zend_hash_quick_find(hosts, NULL, 0, i, (void**)&zpData) ||
48-
Z_TYPE_PP(zpData) != IS_STRING)
49-
{
46+
for (zend_hash_internal_pointer_reset(hosts); zend_hash_has_more_elements(hosts) == SUCCESS; zend_hash_move_forward(hosts))
47+
{
48+
if ((zend_hash_get_current_data(hosts, (void **) &zpData) == FAILURE) || (Z_TYPE_PP(zpData) != IS_STRING))
49+
{
5050
efree(ra);
5151
return NULL;
5252
}
@@ -87,6 +87,8 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b
8787
id = zend_list_insert(redis_sock, le_redis_sock);
8888
#endif
8989
add_property_resource(ra->redis[i], "socket", id);
90+
91+
i++;
9092
}
9193

9294
return ra;

0 commit comments

Comments
 (0)