Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de368c6

Browse files
Fix segfault for php7 and RedisArray
Addresses phpredis#707
1 parent c32e2fe commit de368c6

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

redis_array.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void redis_array_free(RedisArray *ra) {
9191
for(i=0;i<ra->count;i++) {
9292
zval_dtor(&ra->redis[i]);
9393
efree(&ra->redis[i]);
94-
efree(&ra->hosts[i]);
94+
efree(ra->hosts[i]);
9595
}
9696
efree(ra->redis);
9797
efree(ra->hosts);
@@ -213,6 +213,10 @@ PHP_METHOD(RedisArray, __construct)
213213
zend_bool b_lazy_connect = 0;
214214
double d_connect_timeout = 0;
215215

216+
/* Initialize custom functions to 'undefined' */
217+
ZVAL_UNDEF(&z_fun);
218+
ZVAL_UNDEF(&z_dist);
219+
216220
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|a", &z0, &z_opts) == FAILURE) {
217221
RETURN_FALSE;
218222
}
@@ -321,7 +325,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
321325
int key_len;
322326
int i;
323327
zval *redis_inst;
324-
zval z_fun, **z_callargs;
328+
zval z_fun, *z_callargs;
325329
HashPosition pointer;
326330
HashTable *h_args;
327331

@@ -357,27 +361,28 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
357361

358362
/* pass call through */
359363
ZVAL_STRING(&z_fun, cmd); /* method name */
360-
z_callargs = emalloc(argc * sizeof(zval*));
364+
z_callargs = emalloc(argc * sizeof(zval));
361365

362366
/* copy args to array */
363367
for (i = 0, zend_hash_internal_pointer_reset_ex(h_args, &pointer);
364368
(zp_tmp = zend_hash_get_current_data_ex(h_args, &pointer)) != NULL;
365-
++i, zend_hash_move_forward_ex(h_args, &pointer)) {
366-
367-
ZVAL_DUP(z_callargs[i], zp_tmp);
369+
++i, zend_hash_move_forward_ex(h_args, &pointer))
370+
{
371+
ZVAL_DUP(&z_callargs[i], zp_tmp);
372+
// ZVAL_DUP(z_callargs[i], zp_tmp);
368373
}
369374

370375
/* multi/exec */
371376
if(ra->z_multi_exec) {
372-
call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, *z_callargs TSRMLS_CC);
377+
call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
373378
efree(z_callargs);
374379
RETURN_ZVAL(getThis(), 1, 0);
375380
}
376381

377382
/* CALL! */
378383
if(ra->index && b_write_cmd) {
379384
/* call using discarded temp value and extract exec results after. */
380-
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, &z_tmp, argc, *z_callargs TSRMLS_CC);
385+
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, &z_tmp, argc, z_callargs TSRMLS_CC);
381386
zval_dtor(&z_tmp);
382387

383388
/* add keys to index. */
@@ -386,7 +391,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
386391
/* call EXEC */
387392
ra_index_exec(redis_inst, return_value, 0 TSRMLS_CC);
388393
} else { /* call directly through. */
389-
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, *z_callargs TSRMLS_CC);
394+
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
390395

391396
/* check if we have an error. */
392397
if(RA_CALL_FAILED(return_value,cmd) && ra->prev && !b_write_cmd) { /* there was an error reading, try with prev ring. */

0 commit comments

Comments
 (0)