Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/hyperscan/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ static PyObject *Database_info(Database *self, PyObject *args)
}

PyObject *oinfo = PyBytes_FromString(info);
Py_INCREF(oinfo);
free(info);
HS_LOCK_RETURN(oinfo);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/test_hyperscan.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import sys
import tracemalloc

import pytest

import hyperscan
Expand Down Expand Up @@ -355,6 +358,35 @@ def test_database_info(database_block):
assert field + b": " in info_string


@pytest.mark.skipif(
sys.implementation.name != "cpython", reason="requires CPython allocation tracing"
)
@pytest.mark.parametrize(
"db_fixture_name",
["database_block", "database_stream", "database_vector", "database_chimera"],
)
def test_database_info_does_not_retain_results(db_fixture_name, request):
database = request.getfixturevalue(db_fixture_name)
database.info()
already_tracing = tracemalloc.is_tracing()
if not already_tracing:
tracemalloc.start()
try:
trace_filter = [tracemalloc.Filter(True, __file__)]
before = tracemalloc.take_snapshot().filter_traces(trace_filter)
for _ in range(1000):
database.info()
after = tracemalloc.take_snapshot().filter_traces(trace_filter)
retained = sum(
max(change.size_diff, 0) for change in after.compare_to(before, "lineno")
)
# Allow tracing/loop bookkeeping; 1000 leaked results retain at least 70 KiB.
assert retained < 4096
finally:
if not already_tracing:
tracemalloc.stop()


@pytest.mark.parametrize(
"db_fixture_name",
["database_stream", "database_block", "database_vector"],
Expand Down