Skip to content

Commit ebb3541

Browse files
Fixes a memory leak in SCAN, with OPT_SCAN_RETRY enabled.
When you instruct phpredis to retry the scan command in the event of a non zero iterator but zero elements being returned, it was leaking memory, as it did not free the previous result. Addresses phpredis#501
1 parent b1ad543 commit ebb3541

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

redis.c

+7
Original file line numberDiff line numberDiff line change
@@ -7229,6 +7229,13 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
72297229
* an updated iterator.
72307230
*/
72317231
do {
7232+
/* Free our previous reply if we're back in the loop. We know we are
7233+
* if our return_value is an array. */
7234+
if(Z_TYPE_P(return_value) == IS_ARRAY) {
7235+
zval_dtor(return_value);
7236+
ZVAL_NULL(return_value);
7237+
}
7238+
72327239
/* Format our SCAN command */
72337240
cmd_len = redis_build_scan_cmd(&cmd, type, key, key_len, (int)iter,
72347241
pattern, pattern_len, count);

0 commit comments

Comments
 (0)