@@ -252,35 +252,35 @@ PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS,
252
252
void * ctx )
253
253
{
254
254
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 );
256
259
257
260
// Consume response(s) from subscribe, which will vary on argc
258
261
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 ) ) {
261
264
efree (sctx );
262
265
return -1 ;
263
266
}
264
267
265
268
// 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 )
267
270
{
268
- zval_dtor (z_tab );
269
- efree (z_tab );
271
+ zval_dtor (& z_resp );
270
272
efree (sctx );
271
273
return -1 ;
272
274
}
273
275
274
276
// Make sure the command response matches the command we called
275
277
if (strcasecmp (Z_STRVAL_P (z_tmp ), sctx -> kw ) != 0 ) {
276
- zval_dtor (z_tab );
277
- efree (z_tab );
278
+ zval_dtor (& z_resp );
278
279
efree (sctx );
279
280
return -1 ;
280
281
}
281
282
282
- zval_dtor (z_tab );
283
- efree (z_tab );
283
+ zval_dtor (& z_resp );
284
284
}
285
285
286
286
sctx -> cb .retval = & z_ret ;
@@ -293,10 +293,13 @@ PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS,
293
293
HashTable * ht_tab ;
294
294
int tab_idx = 1 , is_pmsg ;
295
295
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 ;
298
301
299
- ht_tab = Z_ARRVAL_P (z_tab );
302
+ ht_tab = Z_ARRVAL_P (& z_resp );
300
303
301
304
if ((z_type = zend_hash_index_find (ht_tab , 0 )) == NULL ||
302
305
Z_TYPE_P (z_type ) != IS_STRING )
@@ -352,15 +355,11 @@ PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS,
352
355
// If we have a return value free it
353
356
if (Z_TYPE (z_ret ) != IS_UNDEF ) zval_ptr_dtor (& z_ret );
354
357
355
- zval_dtor (z_tab );
356
- efree (z_tab );
358
+ zval_dtor (& z_resp );
357
359
}
358
360
359
361
// 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 );
364
363
efree (sctx );
365
364
366
365
return -1 ;
@@ -371,24 +370,25 @@ PHP_REDIS_API int redis_unsubscribe_response(INTERNAL_FUNCTION_PARAMETERS,
371
370
void * ctx )
372
371
{
373
372
subscribeContext * sctx = (subscribeContext * )ctx ;
374
- zval * z_chan , z_ret ;
373
+ zval * z_chan , z_ret , z_resp ;
375
374
int i = 0 ;
376
375
376
+ ZVAL_UNDEF (& z_resp );
377
377
array_init (& z_ret );
378
378
379
379
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 );
381
381
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 )
383
383
{
384
+ if (!Z_ISUNDEF (z_resp )) zval_dtor (& z_resp );
384
385
zval_dtor (& z_ret );
385
386
return -1 ;
386
387
}
387
388
388
389
add_assoc_bool (& z_ret , Z_STRVAL_P (z_chan ), 1 );
389
390
390
- zval_dtor (z_tab );
391
- efree (z_tab );
391
+ zval_dtor (& z_resp );
392
392
i ++ ;
393
393
}
394
394
0 commit comments