Skip to content

Commit 4c1f1bc

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 94e0649 commit 4c1f1bc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

redis.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7152,6 +7152,13 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
71527152
* an updated iterator.
71537153
*/
71547154
do {
7155+
/* Free our previous reply if we're back in the loop. We know we are
7156+
* if our return_value is an array. */
7157+
if(Z_TYPE_P(return_value) == IS_ARRAY) {
7158+
zval_dtor(return_value);
7159+
ZVAL_NULL(return_value);
7160+
}
7161+
71557162
/* Format our SCAN command */
71567163
cmd_len = redis_build_scan_cmd(&cmd, type, key, key_len, (int)iter,
71577164
pattern, pattern_len, count);

0 commit comments

Comments
 (0)