Skip to content

Commit

Permalink
fix: fix memory leaks in indexed_string_column.cpp and insertion_cont…
Browse files Browse the repository at this point in the history
…ains.cpp
  • Loading branch information
Taepper committed Aug 3, 2023
1 parent ffcefd0 commit c2eeac8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/silo/storage/column/indexed_string_column.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IndexedStringColumnPartition {
public:
explicit IndexedStringColumnPartition(common::BidirectionalMap<std::string>& lookup);

[[nodiscard]] roaring::Roaring filter(const std::string& value) const;
[[nodiscard]] std::optional<const roaring::Roaring*> filter(const std::string& value) const;

void insert(const std::string& value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::unique_ptr<silo::query_engine::operators::Operator> InsertionContains::comp
return std::make_unique<operators::BitmapProducer>(
[&]() {
auto search_result = insertion_column.search(position, value);
return OperatorResult(std::move(*search_result.release()));
return OperatorResult(std::move(*search_result));
},
database_partition.sequence_count
);
Expand Down
6 changes: 3 additions & 3 deletions src/silo/query_engine/filter_expressions/string_equals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ std::unique_ptr<silo::query_engine::operators::Operator> StringEquals::compile(
) const {
if (database_partition.columns.indexed_string_columns.contains(column)) {
const auto& string_column = database_partition.columns.indexed_string_columns.at(column);
const roaring::Roaring& bitmap = string_column.filter(value);
const auto bitmap = string_column.filter(value);

if (bitmap.isEmpty()) {
if (bitmap == std::nullopt || bitmap.value()->isEmpty()) {
return std::make_unique<operators::Empty>(database_partition.sequence_count);
}
return std::make_unique<operators::IndexScan>(
new roaring::Roaring(bitmap), database_partition.sequence_count
bitmap.value(), database_partition.sequence_count
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/silo/storage/column/indexed_string_column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ IndexedStringColumnPartition::IndexedStringColumnPartition(
)
: lookup(lookup) {}

roaring::Roaring IndexedStringColumnPartition::filter(const std::string& value) const {
std::optional<const roaring::Roaring*> IndexedStringColumnPartition::filter(const std::string& value
) const {
const auto value_id = lookup.getId(value);
if (value_id.has_value()) {
return indexed_values.at(value_id.value());
return &indexed_values.at(value_id.value());
}
return {};
return std::nullopt;
}

void IndexedStringColumnPartition::insert(const std::string& value) {
Expand Down
6 changes: 3 additions & 3 deletions src/silo/storage/column/indexed_string_column.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ TEST(IndexedStringColumn, shouldReturnTheCorrectFilteredValues) {
under_test.insert("value 1");

const auto result1 = under_test.filter("value 1");
ASSERT_EQ(result1, roaring::Roaring({0, 4}));
ASSERT_EQ(*result1.value(), roaring::Roaring({0, 4}));

const auto result2 = under_test.filter("value 2");
ASSERT_EQ(result2, roaring::Roaring({1, 2}));
ASSERT_EQ(*result2.value(), roaring::Roaring({1, 2}));

const auto result3 = under_test.filter("value that does not exist");
ASSERT_EQ(result3, roaring::Roaring());
ASSERT_EQ(result3, std::nullopt);
}

TEST(IndexedStringColumnPartition, insertValuesToPartition) {
Expand Down

0 comments on commit c2eeac8

Please sign in to comment.