mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-11 15:16:27 +01:00
Fix a low-hanging memory leak found by valgrind in slider code
This commit is contained in:
@@ -447,6 +447,8 @@ void LWSlider::Init(wxWindow * parent,
|
|||||||
mDefaultValue = 0.0f;
|
mDefaultValue = 0.0f;
|
||||||
mDefaultShortcut = false;
|
mDefaultShortcut = false;
|
||||||
mBitmap = NULL;
|
mBitmap = NULL;
|
||||||
|
mThumbBitmap = NULL;
|
||||||
|
mThumbBitmapAllocated = false;
|
||||||
mScrollLine = 1.0f;
|
mScrollLine = 1.0f;
|
||||||
mScrollPage = 5.0f;
|
mScrollPage = 5.0f;
|
||||||
|
|
||||||
@@ -461,7 +463,7 @@ void LWSlider::Init(wxWindow * parent,
|
|||||||
LWSlider::~LWSlider()
|
LWSlider::~LWSlider()
|
||||||
{
|
{
|
||||||
delete mBitmap;
|
delete mBitmap;
|
||||||
if (mOrientation == wxVERTICAL && mThumbBitmap) {
|
if (mThumbBitmapAllocated) {
|
||||||
delete mThumbBitmap;
|
delete mThumbBitmap;
|
||||||
}
|
}
|
||||||
delete mPopWin;
|
delete mPopWin;
|
||||||
@@ -600,18 +602,32 @@ void LWSlider::Draw()
|
|||||||
//
|
//
|
||||||
|
|
||||||
if (mEnabled && mOrientation == wxHORIZONTAL)
|
if (mEnabled && mOrientation == wxHORIZONTAL)
|
||||||
|
{
|
||||||
|
if (mThumbBitmapAllocated)
|
||||||
|
delete mThumbBitmap;
|
||||||
mThumbBitmap = &theTheme.Bitmap( bmpSliderThumb );
|
mThumbBitmap = &theTheme.Bitmap( bmpSliderThumb );
|
||||||
|
mThumbBitmapAllocated = false;
|
||||||
|
}
|
||||||
//vvv \todo Convert this to an image in AllThemeResources, as bmpSliderThumb. Make an alpha also, as for horizontal slider thumb?
|
//vvv \todo Convert this to an image in AllThemeResources, as bmpSliderThumb. Make an alpha also, as for horizontal slider thumb?
|
||||||
else if (mOrientation == wxHORIZONTAL)
|
else if (mOrientation == wxHORIZONTAL)
|
||||||
{
|
{
|
||||||
wxImage thumbImage(wxBitmap(SliderThumbDisabled).ConvertToImage());
|
wxImage thumbImage(wxBitmap(SliderThumbDisabled).ConvertToImage());
|
||||||
|
|
||||||
|
if (mThumbBitmapAllocated)
|
||||||
|
delete mThumbBitmap;
|
||||||
mThumbBitmap = new wxBitmap(thumbImage);
|
mThumbBitmap = new wxBitmap(thumbImage);
|
||||||
|
mThumbBitmapAllocated = true;
|
||||||
|
|
||||||
mThumbBitmap->SetMask(new wxMask(wxBitmap(SliderThumbAlpha), *wxBLACK));
|
mThumbBitmap->SetMask(new wxMask(wxBitmap(SliderThumbAlpha), *wxBLACK));
|
||||||
}
|
}
|
||||||
else if (mEnabled)
|
else if (mEnabled)
|
||||||
{
|
{
|
||||||
wxImage thumbImage(wxBitmap(SliderThumb_Vertical).ConvertToImage());
|
wxImage thumbImage(wxBitmap(SliderThumb_Vertical).ConvertToImage());
|
||||||
|
if (mThumbBitmapAllocated)
|
||||||
|
delete mThumbBitmap;
|
||||||
mThumbBitmap = new wxBitmap(thumbImage);
|
mThumbBitmap = new wxBitmap(thumbImage);
|
||||||
|
mThumbBitmapAllocated = true;
|
||||||
|
|
||||||
mThumbBitmap->SetMask(
|
mThumbBitmap->SetMask(
|
||||||
new wxMask(wxBitmap(SliderThumb_VerticalAlpha), *wxBLACK));
|
new wxMask(wxBitmap(SliderThumb_VerticalAlpha), *wxBLACK));
|
||||||
}
|
}
|
||||||
@@ -619,7 +635,12 @@ void LWSlider::Draw()
|
|||||||
{
|
{
|
||||||
wxImage thumbImage(wxBitmap(
|
wxImage thumbImage(wxBitmap(
|
||||||
SliderThumb_VerticalDisabled).ConvertToImage());
|
SliderThumb_VerticalDisabled).ConvertToImage());
|
||||||
|
|
||||||
|
if (mThumbBitmapAllocated)
|
||||||
|
delete mThumbBitmap;
|
||||||
mThumbBitmap = new wxBitmap(thumbImage);
|
mThumbBitmap = new wxBitmap(thumbImage);
|
||||||
|
mThumbBitmapAllocated = true;
|
||||||
|
|
||||||
mThumbBitmap->SetMask(
|
mThumbBitmap->SetMask(
|
||||||
new wxMask(wxBitmap(SliderThumb_VerticalAlpha), *wxBLACK));
|
new wxMask(wxBitmap(SliderThumb_VerticalAlpha), *wxBLACK));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,9 +211,12 @@ class LWSlider
|
|||||||
bool mIsDragging;
|
bool mIsDragging;
|
||||||
|
|
||||||
wxBitmap *mBitmap;
|
wxBitmap *mBitmap;
|
||||||
wxBitmap *mSelBitmap;
|
|
||||||
wxBitmap *mThumbBitmap;
|
wxBitmap *mThumbBitmap;
|
||||||
wxBitmap *mSelThumbBitmap;
|
|
||||||
|
// True if this object owns *mThumbBitmap (sometimes mThumbBitmap points to
|
||||||
|
// an object we shouldn't delete) -- once we get theming totally right this
|
||||||
|
// should go away
|
||||||
|
bool mThumbBitmapAllocated;
|
||||||
|
|
||||||
wxString mName;
|
wxString mName;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user