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

Skip to content

Commit c610cec

Browse files
Merge branch 'feature/break_sub_loop' into develop
2 parents f78c9f4 + 273dd8f commit c610cec

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

redis.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5622,15 +5622,18 @@ PHP_REDIS_API void generic_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, char *sub
56225622
if (zend_hash_index_find(Z_ARRVAL_P(z_tab), 0, (void**)&tmp) == SUCCESS) {
56235623
type_response = Z_STRVAL_PP(tmp);
56245624
if(strcmp(type_response, sub_cmd) != 0) {
5625-
efree(tmp);
5626-
efree(z_tab);
5625+
efree(tmp);
5626+
zval_dtor(z_tab);
5627+
efree(z_tab);
56275628
RETURN_FALSE;
56285629
}
56295630
} else {
5630-
efree(z_tab);
5631+
zval_dtor(z_tab);
5632+
efree(z_tab);
56315633
RETURN_FALSE;
56325634
}
5633-
efree(z_tab);
5635+
zval_dtor(z_tab);
5636+
efree(z_tab);
56345637

56355638
/* Set a pointer to our return value and to our arguments. */
56365639
z_callback.retval_ptr_ptr = &z_ret;
@@ -5698,10 +5701,19 @@ PHP_REDIS_API void generic_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, char *sub
56985701
break;
56995702
}
57005703

5701-
/* If we have a return value, free it. Note, we could use the return value to break the subscribe loop */
5702-
if(z_ret) zval_ptr_dtor(&z_ret);
5704+
/* Free our return value if we have one. If the return value is a bool
5705+
* that is FALSE, break our subscribe loop and return control to the
5706+
* userland code */
5707+
if (z_ret) {
5708+
if(Z_TYPE_P(z_ret) == IS_BOOL && Z_BVAL_P(z_ret) == 0) {
5709+
zval_ptr_dtor(&z_ret);
5710+
zval_dtor(z_tab);
5711+
efree(z_tab);
5712+
break;
5713+
}
5714+
zval_ptr_dtor(&z_ret);
5715+
}
57035716

5704-
/* TODO: provide a way to break out of the loop. */
57055717
zval_dtor(z_tab);
57065718
efree(z_tab);
57075719
}

0 commit comments

Comments
 (0)