Commit 4090d73a authored by Mikael Salson's avatar Mikael Salson

BinReadStorage: Make sure init() is launched just once.

Launching init several times will allocate several times score_bins and nb_scores
which will cause memory leaks.

This is particularly the case in the WindowExtractor() which calls BinReadStorage
on germline->code but we can have different germlines with the same germline->code.
parent b32b65de
......@@ -14,17 +14,19 @@ void VirtualReadStorage::setMaxNbReadsStored(size_t nb_reads) {
BinReadStorage::BinReadStorage()
:nb_bins(0), bins(NULL), score_bins(NULL), nb_scores(NULL), total_nb_scores(0), max_score(0),
nb_inserted(0), nb_stored(0), smallest_bin_not_empty(~0),label() {}
nb_inserted(0), nb_stored(0), smallest_bin_not_empty(~0),label(),inited(false) {}
void BinReadStorage::init(size_t nb_bins, size_t max_score, const VirtualReadScore *vrs, bool no_list) {
this->all_read_lengths = 0;
if (inited)
return;
this->nb_bins = nb_bins;
this->max_score = max_score;
if (no_list)
bins = NULL;
else
bins = new list<Sequence>[nb_bins+1];
score_bins = new double[nb_bins+1];
nb_scores = new size_t[nb_bins+1];
for (size_t i = 0; i <= nb_bins; i++) {
......@@ -32,6 +34,7 @@ void BinReadStorage::init(size_t nb_bins, size_t max_score, const VirtualReadSco
nb_scores[i] = 0;
}
scorer = vrs;
inited=true;
}
BinReadStorage::~BinReadStorage() {
......
......@@ -78,6 +78,7 @@ class BinReadStorage: public VirtualReadStorage {
size_t nb_stored;
size_t smallest_bin_not_empty;
string label;
bool inited;
public:
BinReadStorage();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment