Skip to content

Commit

Permalink
ASAN fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shelnutt2 committed Nov 25, 2020
1 parent 09bb52c commit dc64ce9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libtiledbvcf/src/read/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Reader::~Reader() {
ctx_->cancel_tasks();
read_state_.async_query.wait();
}

utils::free_htslib_tiledb_context();
}

void Reader::open_dataset(const std::string& dataset_uri) {
Expand Down Expand Up @@ -1399,7 +1401,7 @@ void Reader::prepare_regions_v4(
query_region_contig = &query_regions->back().second;
}
// Start a new query region.
query_region_contig->push_back({});
query_region_contig->emplace_back();
query_region_contig->back().col_min = widened_reg_min;
query_region_contig->back().col_max = reg_max;
query_region_contig->back().contig = r.seq_name;
Expand All @@ -1414,7 +1416,7 @@ void Reader::prepare_regions_v4(
size_t query_regions_size = query_region_pair.second.size();
for (size_t i = 0; i < query_regions_size; i++) {
auto& query_region = query_region_pair.second[i];
for (size_t j = i + 1; j < query_regions->size(); j++) {
for (size_t j = i + 1; j < query_region_pair.second.size(); j++) {
auto& query_region_to_check = query_region_pair.second[j];
if (query_region.col_min <= query_region_to_check.col_max &&
query_region.col_max >= query_region_to_check.col_min) {
Expand Down
9 changes: 9 additions & 0 deletions libtiledbvcf/src/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,15 @@ void set_htslib_tiledb_context(const std::vector<std::string>& tiledb_config) {
}
}

void free_htslib_tiledb_context() {
const std::lock_guard<std::mutex> lock(cfg_mutex);
last_set_config.clear();
if (hfile_tiledb_vfs_ctx != nullptr)
tiledb_ctx_free(&hfile_tiledb_vfs_ctx);
if (hfile_tiledb_vfs_config != nullptr)
tiledb_config_free(&hfile_tiledb_vfs_config);
}

void init_htslib() {
const std::lock_guard<std::mutex> lock(init_mutex);
// trick to init some of htslib's internal data structures for plugins
Expand Down
7 changes: 7 additions & 0 deletions libtiledbvcf/src/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ void set_tiledb_config(
*/
void set_htslib_tiledb_context(const std::vector<std::string>& tiledb_config);

/**
* Free the htslib plugin context
* a thread-safe implementation
*
*/
void free_htslib_tiledb_context();

/**
* Help function to initialize the htslib plugin
*/
Expand Down
4 changes: 4 additions & 0 deletions libtiledbvcf/src/write/writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ namespace vcf {
Writer::Writer() {
}

Writer::~Writer() {
utils::free_htslib_tiledb_context();
}

void Writer::init(const std::string& uri, const std::string& config_str) {
if (!config_str.empty())
set_tiledb_config(config_str);
Expand Down
2 changes: 2 additions & 0 deletions libtiledbvcf/src/write/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class Writer {
/** Constructor. */
Writer();

~Writer();

/**
* Initializes the writer for storing to the given dataset. Opens the array,
* creates the TileDB query, etc.
Expand Down

0 comments on commit dc64ce9

Please sign in to comment.