mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 06:02:26 +08:00
Fix memory leaks:
* Handle deletion of `filter_tree_root` in `sort_fields_guard_t`. * Handle `filter_tree_root` being updated in `Index::static_filter_query_eval`. * Handle deletion of `phrase_result_ids` in `Index::search`.
This commit is contained in:
parent
173e6436df
commit
6acc7d8557
@ -555,7 +555,7 @@ struct sort_by {
|
||||
};
|
||||
|
||||
struct eval_t {
|
||||
filter_node_t* filter_tree_root;
|
||||
filter_node_t* filter_tree_root = nullptr;
|
||||
uint32_t* ids = nullptr;
|
||||
uint32_t size = 0;
|
||||
};
|
||||
|
@ -642,7 +642,7 @@ public:
|
||||
|
||||
Option<bool> search(std::vector<query_tokens_t>& field_query_tokens, const std::vector<search_field_t>& the_fields,
|
||||
const text_match_type_t match_type,
|
||||
filter_node_t* filter_tree_root, std::vector<facet>& facets, facet_query_t& facet_query,
|
||||
filter_node_t*& filter_tree_root, std::vector<facet>& facets, facet_query_t& facet_query,
|
||||
const std::vector<std::pair<uint32_t, uint32_t>>& included_ids,
|
||||
const std::vector<uint32_t>& excluded_ids, std::vector<sort_by>& sort_fields_std,
|
||||
const std::vector<uint32_t>& num_typos, Topster* topster, Topster* curated_topster,
|
||||
|
@ -28,6 +28,8 @@ struct sort_fields_guard_t {
|
||||
|
||||
~sort_fields_guard_t() {
|
||||
for(auto& sort_by_clause: sort_fields_std) {
|
||||
delete sort_by_clause.eval.filter_tree_root;
|
||||
|
||||
if(sort_by_clause.eval.ids) {
|
||||
delete [] sort_by_clause.eval.ids;
|
||||
sort_by_clause.eval.ids = nullptr;
|
||||
@ -1542,6 +1544,11 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
|
||||
std::unique_ptr<search_args> search_params_guard(search_params);
|
||||
|
||||
auto search_op = index->run_search(search_params, name);
|
||||
|
||||
// filter_tree_root might be updated in Index::static_filter_query_eval.
|
||||
filter_tree_root_guard.release();
|
||||
filter_tree_root_guard.reset(filter_tree_root);
|
||||
|
||||
if (!search_op.ok()) {
|
||||
return Option<nlohmann::json>(search_op.code(), search_op.error());
|
||||
}
|
||||
|
@ -2348,7 +2348,7 @@ bool Index::static_filter_query_eval(const override_t* override,
|
||||
if (filter_tree_root == nullptr) {
|
||||
filter_tree_root = new_filter_tree_root;
|
||||
} else {
|
||||
filter_node_t* root = new filter_node_t(AND, filter_tree_root,
|
||||
auto root = new filter_node_t(AND, filter_tree_root,
|
||||
new_filter_tree_root);
|
||||
filter_tree_root = root;
|
||||
}
|
||||
@ -2711,7 +2711,7 @@ void Index::search_infix(const std::string& query, const std::string& field_name
|
||||
|
||||
Option<bool> Index::search(std::vector<query_tokens_t>& field_query_tokens, const std::vector<search_field_t>& the_fields,
|
||||
const text_match_type_t match_type,
|
||||
filter_node_t* filter_tree_root, std::vector<facet>& facets, facet_query_t& facet_query,
|
||||
filter_node_t*& filter_tree_root, std::vector<facet>& facets, facet_query_t& facet_query,
|
||||
const std::vector<std::pair<uint32_t, uint32_t>>& included_ids,
|
||||
const std::vector<uint32_t>& excluded_ids, std::vector<sort_by>& sort_fields_std,
|
||||
const std::vector<uint32_t>& num_typos, Topster* topster, Topster* curated_topster,
|
||||
@ -2797,6 +2797,8 @@ Option<bool> Index::search(std::vector<query_tokens_t>& field_query_tokens, cons
|
||||
// handle phrase searches
|
||||
uint32_t* phrase_result_ids = nullptr;
|
||||
uint32_t phrase_result_count = 0;
|
||||
std::unique_ptr<uint32_t> phrase_result_ids_guard;
|
||||
|
||||
if (!field_query_tokens[0].q_phrases.empty()) {
|
||||
do_phrase_search(num_search_fields, the_fields, field_query_tokens,
|
||||
sort_fields_std, searched_queries, group_limit, group_by_fields,
|
||||
@ -2805,6 +2807,9 @@ Option<bool> Index::search(std::vector<query_tokens_t>& field_query_tokens, cons
|
||||
excluded_result_ids, excluded_result_ids_size, excluded_group_ids, curated_topster,
|
||||
included_ids_map, is_wildcard_query,
|
||||
phrase_result_ids, phrase_result_count);
|
||||
|
||||
phrase_result_ids_guard.reset(phrase_result_ids);
|
||||
|
||||
if (phrase_result_count == 0) {
|
||||
goto process_search_results;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user