8000 Fix subscribe for php7 · jrtkcoder/phpredis@4a37e47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a37e47

Browse files
Fix subscribe for php7
Addresses phpredis#717
1 parent 6d63425 commit 4a37e47

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

library.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -252,35 +252,35 @@ PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS,
252252
void *ctx)
253253
{
254254
subscribeContext *sctx = (subscribeContext*)ctx;
255-
zval *z_tmp, z_ret, z_args[4];
255+
zval *z_tmp, z_ret, z_resp, z_args[4];
256+
257+
/* Initialize our response as undefined */
258+
ZVAL_UNDEF(&z_resp);
256259

257260
// Consume response(s) from subscribe, which will vary on argc
258261
while(sctx->argc--) {
259-
redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab);
260-
if(!z_tab) {
262+
redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, &z_resp);
263+
if(Z_ISUNDEF(z_resp)) {
261264
efree(sctx);
262265
return -1;
263266
}
264267

265268
// We'll need to find the command response
266-
if ((z_tmp = zend_hash_index_find(Z_ARRVAL_P(z_tab), 0)) == NULL)
269+
if ((z_tmp = zend_hash_index_find(Z_ARRVAL_P(&z_resp), 0)) == NULL)
267270
{
268-
zval_dtor(z_tab);
269-
efree(z_tab);
271+
zval_dtor(&z_resp);
270272
efree(sctx);
271273
return -1;
272274
}
273275

274276
// Make sure the command response matches the command we called
275277
if(strcasecmp(Z_STRVAL_P(z_tmp), sctx->kw) !=0) {
276-
zval_dtor(z_tab);
277-
efree(z_tab);
278+
zval_dtor(&z_resp);
278279
efree(sctx);
279280
return -1;
280281
}
281282

282-
zval_dtor(z_tab);
283-
efree(z_tab);
283+
zval_dtor(&z_resp);
284284
}
285285

286286
sctx->cb.retval = &z_ret;
@@ -293,10 +293,13 @@ PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS,
293293
HashTable *ht_tab;
294294
int tab_idx=1, is_pmsg;
295295

296-
redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab);
297-
if(Z_TYPE_P(z_tab) == IS_UNDEF) break;
296+
/* Start as undefined */
297+
ZVAL_UNDEF(&z_resp);
298+
299+
redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, &z_resp);
300+
if (Z_ISUNDEF(z_resp)) break;
298301

299-
ht_tab = Z_ARRVAL_P(z_tab);
302+
ht_tab = Z_ARRVAL_P(&z_resp);
300303

301304
if((z_type = zend_hash_index_find(ht_tab, 0)) == NULL ||
302305
Z_TYPE_P(z_type) != IS_STRING)
@@ -352,15 +355,11 @@ PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS,
352355
// If we have a return value free it
353356
if(Z_TYPE(z_ret) != IS_UNDEF) zval_ptr_dtor(&z_ret);
354357

355-
zval_dtor(z_tab);
356-
efree(z_tab);
358+
zval_dtor(&z_resp);
357359
}
358360

359361
// This is an error state, clean up
360-
if(z_tab) {
361-
zval_dtor(z_tab);
362-
efree(z_tab);
363-
}
362+
if (!Z_ISUNDEF(z_resp)) zval_dtor(&z_resp);
364363
efree(sctx);
365364

366365
return -1;
@@ -371,24 +370,25 @@ PHP_REDIS_API int redis_unsubscribe_response(INTERNAL_FUNCTION_PARAMETERS,
371370
void *ctx)
372371
{
373372
subscribeContext *sctx = (subscribeContext*)ctx;
374-
zval *z_chan, z_ret;
373+
zval *z_chan, z_ret, z_resp;
375374
int i=0;
376375

376+
ZVAL_UNDEF(&z_resp);
377377
array_init(&z_ret);
378378

379379
while(i<sctx->argc) {
380-
redis_sock_read_multibulk_reply_zval( INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab);
380+
redis_sock_read_multibulk_reply_zval( INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, &z_resp);
381381

382-
if(Z_TYPE_P(z_tab) == IS_UNDEF || (z_chan = zend_hash_index_find(Z_ARRVAL_P(z_tab), 1)) == NULL)
382+
if(Z_ISUNDEF(z_resp) || (z_chan = zend_hash_index_find(Z_ARRVAL_P(&z_resp), 1)) == NULL)
383383
{
384+
if (!Z_ISUNDEF(z_resp)) zval_dtor(&z_resp);
384385
zval_dtor(&z_ret);
385386
return -1;
386387
}
387388

388389
add_assoc_bool(&z_ret, Z_STRVAL_P(z_chan), 1);
389390

390-
zval_dtor(z_tab);
391-
efree(z_tab);
391+
zval_dtor(&z_resp);
392392
i++;
393393
}
394394

0 commit comments

Comments
 (0)
0