Skip to content

Commit

Permalink
Closed chromosome name string memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
dzerbino committed Dec 26, 2020
1 parent fa4c062 commit 5a4cdc3
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 11 deletions.
3 changes: 1 addition & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Hold fire on writers
Seekable apply_paste
Memory tracking & cleaning of chrom labels
Read strand in BigBed files?
Memory tracking & cleaning of chrom labels for text files
Read score in BigBed files? => Handling overlapping iterators with value in unit and filter
Read data in VCF file?
HMM app? (requires reverse iterators...)
4 changes: 1 addition & 3 deletions src/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ void computeApplyValues(Multiplexer * apply, ApplyMultiplexerData * data, Buffer
apply->values[i] = *((double*) (wi->data));
WiggleIterator * tmp = wi;
wi = wi->append;
if (tmp->data)
free(tmp->data);
free(tmp);
destroyWiggleIterator(tmp);
i++;
}
} else
Expand Down
2 changes: 1 addition & 1 deletion src/bedReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ WiggleIterator * BedReader(char * filename) {
fprintf(stderr, "Could not open bed file %s\n", filename);
exit(1);
}
WiggleIterator * res = newWiggleIterator(data, &BedReaderPop, &BedReaderSeek, 0);
WiggleIterator * res = newWiggleIteratorChromName(data, &BedReaderPop, &BedReaderSeek, 0);
res->overlaps = true;
return res;
}
2 changes: 1 addition & 1 deletion src/samReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,5 @@ WiggleIterator * SamReader(char * filename) {
}
} else
data->file = stdin;
return newWiggleIterator(data, &SamReaderPop, &SamReaderSeek, 0);
return newWiggleIteratorChromName(data, &SamReaderPop, &SamReaderSeek, 0);
}
2 changes: 1 addition & 1 deletion src/unaryOps.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void CoverageWiggleIteratorPop(WiggleIterator * wi) {
CoverageWiggleIteratorData * data = (CoverageWiggleIteratorData *) wi->data;
WiggleIterator * iter = data->iter;
if (!iter->done) {
if (wi->chrom[0] == '\0')
if (wi->chrom == NULL)
wi->value = 0;

while (fh_notempty(data->heap) && fh_min(data->heap) == wi->finish) {
Expand Down
2 changes: 1 addition & 1 deletion src/vcfReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ WiggleIterator * VcfReader(char * filename) {
fprintf(stderr, "Could not open bed file %s\n", filename);
exit(1);
}
WiggleIterator * res = newWiggleIterator(data, &VcfReaderPop, &VcfReaderSeek, 0);
WiggleIterator * res = newWiggleIteratorChromName(data, &VcfReaderPop, &VcfReaderSeek, 0);
res->value = 1;
res->overlaps = true;
return res;
Expand Down
2 changes: 1 addition & 1 deletion src/wigReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,5 @@ WiggleIterator * WiggleReader(char * f) {
data->file = stdin;
data->readingMode = BED_GRAPH;
data->stop = -1;
return CompressionWiggleIterator(newWiggleIterator(data, &WiggleReaderPop, &WiggleReaderSeek, 0));
return CompressionWiggleIterator(newWiggleIteratorChromName(data, &WiggleReaderPop, &WiggleReaderSeek, 0));
}
17 changes: 16 additions & 1 deletion src/wiggleIterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
#include "wiggleIterator.h"

WiggleIterator * newWiggleIterator(void * data, void (*popFunction)(WiggleIterator *), void (*seek)(WiggleIterator *, const char *, int, int), double default_value) {
WiggleIterator * new = (WiggleIterator *) calloc(1, sizeof(WiggleIterator));
new->data = data;
new->pop = popFunction;
new->seek = seek;
new->chrom = NULL;
new->value = 1; // Default value for non-valued bed tracks;
new->strand = 0; // Default value for non-stranded data;
new->valuePtr = NULL;
new->overlaps = false;
new->append = NULL;
new->default_value = default_value;
pop(new);
return new;
}

WiggleIterator * newWiggleIteratorChromName(void * data, void (*popFunction)(WiggleIterator *), void (*seek)(WiggleIterator *, const char *, int, int), double default_value) {
WiggleIterator * new = (WiggleIterator *) calloc(1, sizeof(WiggleIterator));
new->data = data;
new->pop = popFunction;
Expand All @@ -35,7 +51,6 @@ WiggleIterator * newWiggleIterator(void * data, void (*popFunction)(WiggleIterat

void destroyWiggleIterator(WiggleIterator * wi) {
free(wi->data);
free(wi->chrom);
free(wi);
}

Expand Down
1 change: 1 addition & 0 deletions src/wiggleIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct wiggleIterator_st {
};

WiggleIterator * newWiggleIterator(void * data, void (*pop)(WiggleIterator *), void (*seek)(WiggleIterator *, const char *, int, int), double default_value);
WiggleIterator * newWiggleIteratorChromName(void * data, void (*popFunction)(WiggleIterator *), void (*seek)(WiggleIterator *, const char *, int, int), double default_value);
void pop(WiggleIterator *);
WiggleIterator * CompressionWiggleIterator(WiggleIterator *);

Expand Down

0 comments on commit 5a4cdc3

Please sign in to comment.