Skip to content

Commit

Permalink
fixed: fixed memory leaks in ximadsp.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
WiSo authored and davilla committed Oct 26, 2013
1 parent a5fc05e commit 9cf5e5f
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/cximage-6.0/CxImage/ximadsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@ bool CxImage::Median(long Ksize)

CxImage tmp(*this);
if (!tmp.IsValid()){
free(kernel);
strcpy(info.szLastError,tmp.GetLastError());
return false;
}
Expand Down Expand Up @@ -2424,11 +2425,15 @@ bool CxImage::TextBlur(BYTE threshold, BYTE decay, BYTE max_depth, bool bBlurHor
pPalette = new RGBQUAD[head.biClrUsed];
memcpy(pPalette, GetPalette(),GetPaletteSize());
if (!IncreaseBpp(24))
{
delete [] pPalette;
return false;
}
}

CxImage tmp(*this);
if (!tmp.IsValid()){
delete [] pPalette;
strcpy(info.szLastError,tmp.GetLastError());
return false;
}
Expand Down Expand Up @@ -2484,12 +2489,16 @@ bool CxImage::GaussianBlur(float radius /*= 1.0f*/, CxImage* iDst /*= 0*/)
pPalette = new RGBQUAD[head.biClrUsed];
memcpy(pPalette, GetPalette(),GetPaletteSize());
if (!IncreaseBpp(24))
{
delete [] pPalette;
return false;
}
}

CxImage tmp_x(*this, false, true, true);
if (!tmp_x.IsValid()){
strcpy(info.szLastError,tmp_x.GetLastError());
delete [] pPalette;
return false;
}

Expand All @@ -2508,7 +2517,7 @@ bool CxImage::GaussianBlur(float radius /*= 1.0f*/, CxImage* iDst /*= 0*/)
double dbScaler = 50.0f/head.biHeight;

// blur the rows
for (y=0;y<head.biHeight;y++)
for (y=0;y<head.biHeight;y++)
{
if (info.nEscape) break;
info.nProgress = (long)(y*dbScaler);
Expand All @@ -2518,15 +2527,16 @@ bool CxImage::GaussianBlur(float radius /*= 1.0f*/, CxImage* iDst /*= 0*/)

CxImage tmp_y(tmp_x, false, true, true);
if (!tmp_y.IsValid()){
delete [] pPalette;
strcpy(info.szLastError,tmp_y.GetLastError());
return false;
}

CImageIterator itDst(&tmp_y);

// blur the cols
BYTE* cur_col = (BYTE*)malloc(bypp*head.biHeight);
BYTE* dest_col = (BYTE*)malloc(bypp*head.biHeight);
BYTE* cur_col = (BYTE*)malloc(bypp*head.biHeight);
BYTE* dest_col = (BYTE*)malloc(bypp*head.biHeight);

dbScaler = 50.0f/head.biWidth;

Expand Down Expand Up @@ -2594,11 +2604,15 @@ bool CxImage::SelectiveBlur(float radius, BYTE threshold, CxImage* iDst)
pPalette = new RGBQUAD[head.biClrUsed];
memcpy(pPalette, GetPalette(),GetPaletteSize());
if (!Tmp.IncreaseBpp(24))
{
delete [] pPalette;
return false;
}
}

CxImage Dst(Tmp, true, true, true);
if (!Dst.IsValid()){
delete [] pPalette;
strcpy(info.szLastError,Dst.GetLastError());
return false;
}
Expand All @@ -2608,6 +2622,7 @@ bool CxImage::SelectiveBlur(float radius, BYTE threshold, CxImage* iDst)
BYTE thresh_up = (BYTE)min(255,(int)(128 + threshold));
long kernel[]={-100,-100,-100,-100,801,-100,-100,-100,-100};
if (!Tmp.Filter(kernel,3,800,128)){
delete [] pPalette;
strcpy(info.szLastError,Tmp.GetLastError());
return false;
}
Expand Down Expand Up @@ -2644,6 +2659,7 @@ bool CxImage::SelectiveBlur(float radius, BYTE threshold, CxImage* iDst)
//blur the image (only in the selected pixels)
Dst.SelectionCopy(Tmp);
if (!Dst.GaussianBlur(radius)){
delete [] pPalette;
strcpy(info.szLastError,Dst.GetLastError());
return false;
}
Expand Down Expand Up @@ -3493,12 +3509,18 @@ bool CxImage::FloodFill(const long xStart, const long yStart, const RGBQUAD cFil
pPalette = new RGBQUAD[head.biClrUsed];
memcpy(pPalette, GetPalette(),GetPaletteSize());
if (!IncreaseBpp(24))
{
delete [] pPalette;
return false;
}
}

BYTE* pFillMask = (BYTE*)calloc(head.biWidth * head.biHeight,1);
if (!pFillMask)
{
delete [] pPalette;
return false;
}

//------------------------------------- Begin of Flood Fill
POINT offset[4] = {{-1,0},{0,-1},{1,0},{0,1}};
Expand Down

0 comments on commit 9cf5e5f

Please sign in to comment.