Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leak in shiftBed #1094

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions src/shiftBed/shiftBed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,42 @@
#include "lineFileUtilities.h"
#include "shiftBed.h"

BedShift::BedShift(string &bedFile, string &genomeFile, float shiftMinus,
float shiftPlus, bool fractional, bool printHeader) {

_bedFile = bedFile;
_genomeFile = genomeFile;
_shiftMinus = shiftMinus;
_shiftPlus = shiftPlus;
_fractional = fractional;
_printHeader = printHeader;

_bed = new BedFile(bedFile);
_genome = new GenomeFile(genomeFile);

BedShift::BedShift(const string &bedFile, const string &genomeFile, float shiftMinus,
float shiftPlus, bool fractional, bool printHeader) :
_bedFile(bedFile),
_genomeFile(genomeFile),
_shiftMinus(shiftMinus),
_shiftPlus(shiftPlus),
_fractional(fractional),
_printHeader(printHeader),
_bed(_bedFile),
_genome(genomeFile)
{
// get going, shift it around.
ShiftBed();
}

BedShift::~BedShift(void) {}

void BedShift::ShiftBed() {

BED bedEntry; // used to store the current BED line from the BED file.

_bed->Open();
_bed.Open();
// report header first if asked.
if (_printHeader == true) {
_bed->PrintHeader();
_bed.PrintHeader();
}
while (_bed->GetNextBed(bedEntry)) {
if (_bed->_status == BED_VALID) {
while (_bed.GetNextBed(bedEntry)) {
if (_bed._status == BED_VALID) {
AddShift(bedEntry);
_bed->reportBedNewLine(bedEntry);
_bed.reportBedNewLine(bedEntry);
}
}
_bed->Close();
_bed.Close();
}

void BedShift::AddShift(BED &bed) {

CHRPOS chromSize = (CHRPOS)_genome->getChromSize(bed.chrom);
CHRPOS chromSize = _genome.getChromSize(bed.chrom);

double shift;

Expand Down
12 changes: 3 additions & 9 deletions src/shiftBed/shiftBed.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ class BedShift {
public:

// constructor
BedShift(string &bedFile, string &genomeFile, float shiftMinus, float shiftPlus, bool fractional, bool printHeader);

// destructor
~BedShift(void);


BedShift(const string &bedFile, const string &genomeFile, float shiftMinus, float shiftPlus, bool fractional, bool printHeader);

private:

Expand All @@ -45,11 +40,10 @@ class BedShift {
bool _fractional;
bool _printHeader;

BedFile *_bed;
GenomeFile *_genome;
BedFile _bed;
GenomeFile _genome;

// methods

void ShiftBed();

// method to add requested "slop" to a single BED entry
Expand Down