Skip to content
Snippets Groups Projects
Commit 250d6564 authored by Lieven Govaerts's avatar Lieven Govaerts Committed by Andrews Sobral
Browse files

Fix a memory leak when destroying the IndependentMultimodal object. (#109)

* Fix a memory leak when deosrtying the IndependentMultimodal object. Ensure internally used objects
stored in arrays are destroyed correctly.

* package_bgs/IMBS/IMBS.hpp
  (Bins, BgModel): Add initialize function and destructor to cover the lifecycle of its member variables.

* package_bgs/IMBS/IMBS.cpp
  (BackgroundSubtractorIMBS::initialize): Use the new Bins and BgModel initialize functions.

* Whitespace-only fix.

* package_bgs/IMBS/IMBS.hpp
  (~BgModel, ~Bins): Cleanup whitespaces.
parent cc483c60
No related branches found
No related tags found
No related merge requests found
......@@ -173,15 +173,8 @@ void BackgroundSubtractorIMBS::initialize(Size frameSize, int frameType)
for (unsigned int p = 0; p < numPixels; ++p)
{
bgBins[p].binValues = new Vec3b[numSamples];
bgBins[p].binHeights = new uchar[numSamples];
bgBins[p].isFg = new bool[numSamples];
bgModel[p].values = new Vec3b[maxBgBins];
bgModel[p].isValid = new bool[maxBgBins];
bgModel[p].isValid[0] = false;
bgModel[p].isFg = new bool[maxBgBins];
bgModel[p].counter = new uchar[maxBgBins];
bgBins[p].initialize(numSamples);
bgModel[p].initialize(maxBgBins);
}
}
......
......@@ -131,16 +131,39 @@ private:
Mat initialMsgRGB;
//struct for modeling the background values for a single pixel
typedef struct {
typedef struct Bins {
void initialize(unsigned int numSamples) {
binValues = new Vec3b[numSamples];
binHeights = new uchar[numSamples];
isFg = new bool[numSamples];
}
~Bins() {
if (binValues) { delete[] binValues; }
if (binHeights) { delete[] binHeights; }
if (isFg) { delete[] isFg; }
}
Vec3b* binValues;
uchar* binHeights;
bool* isFg;
} Bins;
Bins* bgBins;
public:
//struct for modeling the background values for the entire frame
typedef struct {
typedef struct BgModel {
void initialize(unsigned int maxBgBins) {
values = new Vec3b[maxBgBins];
isValid = new bool[maxBgBins];
isValid[0] = false;
isFg = new bool[maxBgBins];
counter = new uchar[maxBgBins];
}
~BgModel() {
if (values) { delete[] values; }
if (isValid) { delete[] isValid; }
if (isFg) { delete[] isFg; }
if (counter) { delete[] counter; }
}
Vec3b* values;
bool* isValid;
bool* isFg;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment