Skip to content

Commit

Permalink
[2.6] MOD-6599: Remove double free in IntersectIterator_Free() (#4543)
Browse files Browse the repository at this point in the history
* Avoid double free of bestIt

* Revert "Avoid double free of bestIt"

This reverts commit b0988be.

* Avoid double free of bestIt, without line ending changes.
  • Loading branch information
nafraf committed Mar 21, 2024
1 parent 4ab44e7 commit 1330915
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/index.c
@@ -1,9 +1,9 @@
/*
* Copyright Redis Ltd. 2016 - present
* Licensed under your choice of the Redis Source Available License 2.0 (RSALv2) or
* the Server Side Public License v1 (SSPLv1).
*/

/*
* Copyright Redis Ltd. 2016 - present
* Licensed under your choice of the Redis Source Available License 2.0 (RSALv2) or
* the Server Side Public License v1 (SSPLv1).
*/

#include "forward_index.h"
#include "index.h"
#include "varint.h"
Expand Down Expand Up @@ -652,6 +652,9 @@ void IntersectIterator_Free(IndexIterator *it) {
IntersectIterator *ui = it->ctx;
for (int i = 0; i < ui->num; i++) {
if (ui->its[i] != NULL) {
if(ui->its[i] == ui->bestIt) {
ui->bestIt = NULL;
}
ui->its[i]->Free(ui->its[i]);
}
// IndexResult_Free(&ui->currentHits[i]);
Expand Down
19 changes: 19 additions & 0 deletions tests/pytests/test_issues.py
Expand Up @@ -5,6 +5,7 @@

from common import *
from RLTest import Env
from random import randint

def test_1282(env):
conn = getConnectionByEnv(env)
Expand Down Expand Up @@ -1018,3 +1019,21 @@ def expect_error(cmd):
# Test Lua
for cmd in cmds:
env.expect('EVAL', f'return redis.call{cmd}', '0').error().contains(expect_error(cmd))

def test_mod_6599_query(env):
docs = 1000
for i in range(docs):
key = "{doc}:" + str(i)
numstr = '' . join([str(randint(0,9)) for _ in range(11)])
env.cmd("HSET", key, "id", "docum" + numstr, "gender", i%2)

env.cmd('FT.CREATE idx ON HASH SCHEMA id TEXT gender NUMERIC')
waitForIndex(env, 'idx')

# Test that the query is not crashing if run multiple times
for i in range(12):
res = env.cmd("FT.SEARCH", "idx",
"(@id: ~doc* ) | (@id: ~docum*)",
"LIMIT", "0", "50", "NOCONTENT",
"FILTER", "gender", "1", "1")
env.assertEqual(res[0], docs/2)

0 comments on commit 1330915

Please sign in to comment.