https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3fa95ab912fc38e44d88c…
commit 3fa95ab912fc38e44d88c7a5bce90b0ea9cff697
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Wed Dec 25 15:46:29 2019 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Wed Dec 25 15:46:29 2019 +0900
[MSPAINT] Fix memory leak of SelectionModel (#2169)
- Initialize all members in SelectionModel's ctor.
- Add SelectionModel's dtor.
---
base/applications/mspaint/selectionmodel.cpp | 24 +++++++++++++++++++++---
base/applications/mspaint/selectionmodel.h | 6 ++++++
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/base/applications/mspaint/selectionmodel.cpp
b/base/applications/mspaint/selectionmodel.cpp
index a476594ccc0..53f1395ca0a 100644
--- a/base/applications/mspaint/selectionmodel.cpp
+++ b/base/applications/mspaint/selectionmodel.cpp
@@ -4,6 +4,7 @@
* FILE: base/applications/mspaint/selectionmodel.cpp
* PURPOSE: Keep track of selection parameters, notify listeners
* PROGRAMMERS: Benedikt Freisen
+ * Katayama Hirofumi MZ
*/
/* INCLUDES *********************************************************/
@@ -13,11 +14,28 @@
/* FUNCTIONS ********************************************************/
SelectionModel::SelectionModel()
+ : m_hDC(CreateCompatibleDC(NULL))
+ , m_hBm(NULL)
+ , m_hMask(NULL)
+ , m_ptStack(NULL)
+ , m_iPtSP(0)
{
- m_ptStack = NULL;
- m_iPtSP = 0;
+ SetRectEmpty(&m_rcSrc);
+ 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()
diff --git a/base/applications/mspaint/selectionmodel.h
b/base/applications/mspaint/selectionmodel.h
index 297d70b161f..c52c743a7af 100644
--- a/base/applications/mspaint/selectionmodel.h
+++ b/base/applications/mspaint/selectionmodel.h
@@ -4,6 +4,7 @@
* FILE: base/applications/mspaint/selectionmodel.h
* PURPOSE: Keep track of selection parameters, notify listeners
* PROGRAMMERS: Benedikt Freisen
+ * Katayama Hirofumi MZ
*/
#pragma once
@@ -39,6 +40,7 @@ private:
public:
SelectionModel();
+ ~SelectionModel();
void ResetPtStack();
void PushToPtStack(LONG x, LONG y);
void CalculateBoundingBoxAndContents(HDC hDCImage);
@@ -64,4 +66,8 @@ public:
LONG GetDestRectLeft();
LONG GetDestRectTop();
void DrawTextToolText(HDC hDCImage, COLORREF crFg, COLORREF crBg, BOOL bBgTransparent
= FALSE);
+
+private:
+ SelectionModel(const SelectionModel&);
+ SelectionModel& operator=(const SelectionModel&);
};