Skip to content

Commit

Permalink
Gripper: Remove any modifications post destruction.
Browse files Browse the repository at this point in the history
- Gripper is a suicidal class and we need to make sure no modification to the
  class take place after the destructor is called. Doing so screws up the
  heap. (See case WM_LBUTTONUP, WM_NCLBUTTONUP and DMM_CANCEL_MOVE in
  Gripper::runProc(.))

- The self pointer passed as parameter in Gripper::startGrip is removed since
  it was redundant.

Signed-off-by: Jocelyn Legault <jocelynlegault@gmail.com>
Signed-off-by: Thell Fowler <git@tbfowler.name>
  • Loading branch information
joce authored and Thell Fowler committed Oct 21, 2009
1 parent ed1348f commit cdeddfb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
2 changes: 0 additions & 2 deletions PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "Tabbar.h"
#include "npp_winver.h"

#include "Debug/npp_debug.h"

#ifndef WH_MOUSE_LL
#define WH_MOUSE_LL 14
#endif
Expand Down
5 changes: 3 additions & 2 deletions PowerEditor/src/WinControls/DockingWnd/DockingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ LRESULT DockingManager::runProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM l
}
case DMM_MOVE:
{
Gripper* pGripper = new Gripper;
// Gripper will self delete on WM_DESTROY
Gripper* pGripper = new Gripper;
pGripper->init(_hInst, _hParent);
pGripper->startGrip((DockingCont*)lParam, this, pGripper);
pGripper->startGrip((DockingCont*)lParam, this);
break;
}
case DMM_MOVE_SPLITTER:
Expand Down
9 changes: 2 additions & 7 deletions PowerEditor/src/WinControls/DockingWnd/Gripper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ Gripper::Gripper()
_startMovingFromTab = FALSE;
_iItem = 0;

_pRes = 0;

_hdc = NULL;
_hbm = NULL;
_hbrush = NULL;
Expand All @@ -108,11 +106,10 @@ Gripper::Gripper()
}


void Gripper::startGrip(DockingCont* pCont, DockingManager* pDockMgr, void* pRes)
void Gripper::startGrip(DockingCont* pCont, DockingManager* pDockMgr)
{
_pDockMgr = pDockMgr;
_pCont = pCont;
_pRes = pRes;

_pDockMgr->getDockInfo(&_dockData);

Expand Down Expand Up @@ -209,7 +206,6 @@ LRESULT Gripper::runProc(UINT message, WPARAM wParam, LPARAM lParam)
onButtonUp();

::DestroyWindow(_hSelf);
_hSelf = NULL;
return TRUE;
}
case DMM_CANCEL_MOVE:
Expand All @@ -228,15 +224,14 @@ LRESULT Gripper::runProc(UINT message, WPARAM wParam, LPARAM lParam)
::UnhookWindowsHookEx(hookKeyboard);

::DestroyWindow(_hSelf);
_hSelf = NULL;
return FALSE;
}
case WM_DESTROY:
{
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
::SetWindowPos(_hParent, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
_pCont->focusClient();
delete _pRes;
delete this;
break;
}
default:
Expand Down
5 changes: 1 addition & 4 deletions PowerEditor/src/WinControls/DockingWnd/Gripper.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Gripper
_hParent = hParent;
};

void startGrip(DockingCont* pCont, DockingManager* pDockMgr, void* pRes);
void startGrip(DockingCont* pCont, DockingManager* pDockMgr);

~Gripper() {
if (_hdc) {
Expand Down Expand Up @@ -121,9 +121,6 @@ protected :
RECT _rcItem;
TCITEM _tcItem;

// resource pointer of THIS class
void *_pRes;

HDC _hdc;
HBITMAP _hbm;
HBRUSH _hbrush;
Expand Down

0 comments on commit cdeddfb

Please sign in to comment.