[MSPAINT] Fix memory leak of SelectionModel (#2169)

- Initialize all members in SelectionModel's ctor.
- Add SelectionModel's dtor.
This commit is contained in:
Katayama Hirofumi MZ 2019-12-25 15:46:29 +09:00 committed by GitHub
parent 1d14463947
commit 3fa95ab912
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View file

@ -4,6 +4,7 @@
* FILE: base/applications/mspaint/selectionmodel.cpp * FILE: base/applications/mspaint/selectionmodel.cpp
* PURPOSE: Keep track of selection parameters, notify listeners * PURPOSE: Keep track of selection parameters, notify listeners
* PROGRAMMERS: Benedikt Freisen * PROGRAMMERS: Benedikt Freisen
* Katayama Hirofumi MZ
*/ */
/* INCLUDES *********************************************************/ /* INCLUDES *********************************************************/
@ -13,11 +14,28 @@
/* FUNCTIONS ********************************************************/ /* FUNCTIONS ********************************************************/
SelectionModel::SelectionModel() SelectionModel::SelectionModel()
: m_hDC(CreateCompatibleDC(NULL))
, m_hBm(NULL)
, m_hMask(NULL)
, m_ptStack(NULL)
, m_iPtSP(0)
{ {
m_ptStack = NULL; SetRectEmpty(&m_rcSrc);
m_iPtSP = 0; SetRectEmpty(&m_rcDest);
}
m_hDC = CreateCompatibleDC(NULL); SelectionModel::~SelectionModel()
{
DeleteDC(m_hDC);
ResetPtStack();
if (m_hBm)
{
DeleteObject(m_hBm);
}
if (m_hMask)
{
DeleteObject(m_hMask);
}
} }
void SelectionModel::ResetPtStack() void SelectionModel::ResetPtStack()

View file

@ -4,6 +4,7 @@
* FILE: base/applications/mspaint/selectionmodel.h * FILE: base/applications/mspaint/selectionmodel.h
* PURPOSE: Keep track of selection parameters, notify listeners * PURPOSE: Keep track of selection parameters, notify listeners
* PROGRAMMERS: Benedikt Freisen * PROGRAMMERS: Benedikt Freisen
* Katayama Hirofumi MZ
*/ */
#pragma once #pragma once
@ -39,6 +40,7 @@ private:
public: public:
SelectionModel(); SelectionModel();
~SelectionModel();
void ResetPtStack(); void ResetPtStack();
void PushToPtStack(LONG x, LONG y); void PushToPtStack(LONG x, LONG y);
void CalculateBoundingBoxAndContents(HDC hDCImage); void CalculateBoundingBoxAndContents(HDC hDCImage);
@ -64,4 +66,8 @@ public:
LONG GetDestRectLeft(); LONG GetDestRectLeft();
LONG GetDestRectTop(); LONG GetDestRectTop();
void DrawTextToolText(HDC hDCImage, COLORREF crFg, COLORREF crBg, BOOL bBgTransparent = FALSE); void DrawTextToolText(HDC hDCImage, COLORREF crFg, COLORREF crBg, BOOL bBgTransparent = FALSE);
private:
SelectionModel(const SelectionModel&);
SelectionModel& operator=(const SelectionModel&);
}; };