@@ -32,8 +32,7 @@ extern zend_class_entry *redis_ce;
32
32
RedisArray *
33
33
ra_load_hosts (RedisArray * ra , HashTable * hosts , long retry_interval , zend_bool b_lazy_connect TSRMLS_DC )
34
34
{
35
- int i , host_len , id ;
36
- int count = zend_hash_num_elements (hosts );
35
+ int i = 0 , host_len , id ;
37
36
char * host , * p ;
38
37
short port ;
39
38
zval * * zpData , z_cons , z_ret ;
@@ -43,10 +42,10 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b
43
42
ZVAL_STRING (& z_cons , "__construct" , 0 );
44
43
45
44
/* 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
- {
45
+ for ( zend_hash_internal_pointer_reset ( hosts ); zend_hash_has_more_elements ( hosts ) == SUCCESS ; zend_hash_move_forward ( hosts ))
46
+ {
47
+ if (( zend_hash_get_current_data ( hosts , ( void * * ) & zpData ) == FAILURE ) || ( Z_TYPE_PP (zpData ) != IS_STRING ))
48
+ {
50
49
efree (ra );
51
50
return NULL ;
52
51
}
@@ -87,6 +86,8 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b
87
86
id = zend_list_insert (redis_sock , le_redis_sock );
88
87
#endif
89
88
add_property_resource (ra -> redis [i ], "socket" , id );
89
+
90
+ i ++ ;
90
91
}
91
92
92
93
return ra ;
@@ -346,19 +347,9 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev
346
347
}
347
348
ra -> prev = hosts_prev ? ra_make_array (hosts_prev , z_fun , z_dist , NULL , b_index , b_pconnect , retry_interval , b_lazy_connect , connect_timeout TSRMLS_CC ) : NULL ;
348
349
349
- /* copy function if provided */
350
- if (z_fun ) {
351
- MAKE_STD_ZVAL (ra -> z_fun );
352
- * ra -> z_fun = * z_fun ;
353
- zval_copy_ctor (ra -> z_fun );
354
- }
355
-
356
- /* copy distributor if provided */
357
- if (z_dist ) {
358
- MAKE_STD_ZVAL (ra -> z_dist );
359
- * ra -> z_dist = * z_dist ;
360
- zval_copy_ctor (ra -> z_dist );
361
- }
350
+ /* Set hash function and distribtor if provided */
351
+ ra -> z_fun = z_fun ;
352
+ ra -> z_dist = z_dist ;
362
353
363
354
return ra ;
364
355
}
@@ -469,15 +460,15 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
469
460
470
461
if (ra -> z_dist ) {
471
462
if (!ra_call_distributor (ra , key , key_len , & pos TSRMLS_CC )) {
472
- return NULL ;
463
+ efree (out );
464
+ return NULL ;
473
465
}
474
466
}
475
467
else {
476
468
uint64_t h64 ;
477
469
478
470
/* hash */
479
471
hash = rcrc32 (out , out_len );
480
- efree (out );
481
472
482
473
/* get position on ring */
483
474
h64 = hash ;
@@ -487,6 +478,9 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
487
478
}
488
479
if (out_pos ) * out_pos = pos ;
489
480
481
+ /* cleanup */
482
+ efree (out );
483
+
490
484
return ra -> redis [pos ];
491
485
}
492
486
@@ -510,7 +504,7 @@ ra_find_key(RedisArray *ra, zval *z_args, const char *cmd, int *key_len) {
510
504
int key_pos = 0 ; /* TODO: change this depending on the command */
511
505
512
506
if ( zend_hash_num_elements (Z_ARRVAL_P (z_args )) == 0
513
- || zend_hash_quick_find (Z_ARRVAL_P (z_args ), NULL , 0 , key_pos , (void * * )& zp_tmp ) == FAILURE
507
+ || zend_hash_index_find (Z_ARRVAL_P (z_args ), key_pos , (void * * ) & zp_tmp ) == FAILURE
514
508
|| Z_TYPE_PP (zp_tmp ) != IS_STRING ) {
515
509
516
510
return NULL ;
@@ -553,7 +547,7 @@ ra_index_change_keys(const char *cmd, zval *z_keys, zval *z_redis TSRMLS_DC) {
553
547
/* prepare keys */
554
548
for (i = 0 ; i < argc - 1 ; ++ i ) {
555
549
zval * * zpp ;
556
- zend_hash_quick_find (Z_ARRVAL_P (z_keys ), NULL , 0 , i , (void * * )& zpp );
550
+ zend_hash_index_find (Z_ARRVAL_P (z_keys ), i , (void * * )& zpp );
557
551
z_args [i + 1 ] = * zpp ;
558
552
}
559
553
@@ -653,7 +647,7 @@ ra_index_exec(zval *z_redis, zval *return_value, int keep_all TSRMLS_DC) {
653
647
if (keep_all ) {
654
648
* return_value = z_ret ;
655
649
zval_copy_ctor (return_value );
656
- } else if (zend_hash_quick_find (Z_ARRVAL (z_ret ), NULL , 0 , 0 , (void * * )& zp_tmp ) != FAILURE ) {
650
+ } else if (zend_hash_index_find (Z_ARRVAL (z_ret ), 0 , (void * * )& zp_tmp ) != FAILURE ) {
657
651
* return_value = * * zp_tmp ;
658
652
zval_copy_ctor (return_value );
659
653
}
@@ -889,7 +883,7 @@ ra_expire_key(const char *key, int key_len, zval *z_to, long ttl TSRMLS_DC) {
889
883
static zend_bool
890
884
ra_move_zset (const char * key , int key_len , zval * z_from , zval * z_to , long ttl TSRMLS_DC ) {
891
885
892
- zval z_fun_zrange , z_fun_zadd , z_ret , * z_args [4 ], * * z_zadd_args , * * z_score_pp ;
886
+ zval z_fun_zrange , z_fun_zadd , z_ret , z_ret_dest , * z_args [4 ], * * z_zadd_args , * * z_score_pp ;
893
887
int count ;
894
888
HashTable * h_zset_vals ;
895
889
char * val ;
@@ -958,7 +952,7 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
958
952
ZVAL_STRINGL (& z_fun_zadd , "ZADD" , 4 , 0 );
959
953
MAKE_STD_ZVAL (z_zadd_args [0 ]);
960
954
ZVAL_STRINGL (z_zadd_args [0 ], key , key_len , 0 );
961
- call_user_function (& redis_ce -> function_table , & z_to , & z_fun_zadd , & z_ret , 1 + 2 * count , z_zadd_args TSRMLS_CC );
955
+ call_user_function (& redis_ce -> function_table , & z_to , & z_fun_zadd , & z_ret_dest , 1 + 2 * count , z_zadd_args TSRMLS_CC );
962
956
963
957
/* Expire if needed */
964
958
ra_expire_key (key , key_len , z_to , ttl TSRMLS_CC );
@@ -968,6 +962,11 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
968
962
efree (z_zadd_args [i ]);
969
963
}
970
964
965
+ zval_dtor (& z_ret );
966
+
967
+ /* Free the array itself */
968
+ efree (z_zadd_args );
969
+
971
970
return 1 ;
972
971
}
973
972
@@ -1023,7 +1022,7 @@ ra_move_string(const char *key, int key_len, zval *z_from, zval *z_to, long ttl
1023
1022
static zend_bool
1024
1023
ra_move_hash (const char * key , int key_len , zval * z_from , zval * z_to , long ttl TSRMLS_DC ) {
1025
1024
1026
- zval z_fun_hgetall , z_fun_hmset , z_ret , * z_args [2 ];
1025
+ zval z_fun_hgetall , z_fun_hmset , z_ret , z_ret_dest , * z_args [2 ];
1027
1026
1028
1027
/* run HGETALL on source */
1029
1028
MAKE_STD_ZVAL (z_args [0 ]);
@@ -1041,13 +1040,14 @@ ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
1041
1040
ZVAL_STRINGL (& z_fun_hmset , "HMSET" , 5 , 0 );
1042
1041
ZVAL_STRINGL (z_args [0 ], key , key_len , 0 );
1043
1042
z_args [1 ] = & z_ret ; /* copy z_ret to arg 1 */
1044
- call_user_function (& redis_ce -> function_table , & z_to , & z_fun_hmset , & z_ret , 2 , z_args TSRMLS_CC );
1043
+ call_user_function (& redis_ce -> function_table , & z_to , & z_fun_hmset , & z_ret_dest , 2 , z_args TSRMLS_CC );
1045
1044
1046
1045
/* Expire if needed */
1047
1046
ra_expire_key (key , key_len , z_to , ttl TSRMLS_CC );
1048
1047
1049
1048
/* cleanup */
1050
1049
efree (z_args [0 ]);
1050
+ zval_dtor (& z_ret );
1051
1051
1052
1052
return 1 ;
1053
1053
}
@@ -1109,7 +1109,11 @@ ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
1109
1109
* (z_sadd_args [i + 1 ]) = * * z_data_pp ;
1110
1110
zval_copy_ctor (z_sadd_args [i + 1 ]);
1111
1111
}
1112
- call_user_function (& redis_ce -> function_table , & z_to , & z_fun_sadd , & z_ret , count + 1 , z_sadd_args TSRMLS_CC );
1112
+
1113
+ /* Clean up our input return value */
1114
+ zval_dtor (& z_ret );
1115
+
1116
+ call_user_function (& redis_ce -> function_table , & z_to , & z_fun_sadd , & z_ret , count + 1 , z_sadd_args TSRMLS_CC );
1113
1117
1114
1118
/* Expire if needed */
1115
1119
ra_expire_key (key , key_len , z_to , ttl TSRMLS_CC );
@@ -1123,6 +1127,9 @@ ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
1123
1127
}
1124
1128
efree (z_sadd_args );
1125
1129
1130
+ /* Clean up our output return value */
1131
+ zval_dtor (& z_ret );
1132
+
1126
1133
return 1 ;
1127
1134
}
1128
1135
0 commit comments