Skip to content

Commit f1eb29c

Browse files
committed
[LINT] error 1740
Pointer member 'Symbol' (Location) not directly freed or zero'ed by destructor. *NOTE of importance to the maintainer*: There is a very real potential for leaks in MenuManager.cpp, line 605. There is nothing preventing m_funcItems to be allocated more than once. Signed-off-by: Jocelyn Legault <jocelynlegault@gmail.com>
1 parent e84165a commit f1eb29c

4 files changed

Lines changed: 77 additions & 18 deletions

File tree

PythonScript/src/ConsoleDialog.cpp

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ ConsoleDialog::ConsoleDialog(const ConsoleDialog& other) :
3434
m_hInput(other.m_hInput),
3535
m_console(other.m_console),
3636
m_prompt(other.m_prompt),
37-
m_originalInputWndProc(other.m_originalInputWndProc),
38-
m_hTabIcon(other.m_hTabIcon),
37+
m_originalInputWndProc(NULL),
38+
m_hTabIcon(NULL),
3939
m_history(other.m_history),
4040
m_historyIter(other.m_historyIter),
4141
m_changes(other.m_changes),
4242
m_currentHistory(other.m_currentHistory),
4343
m_runButtonIsRun(other.m_runButtonIsRun),
44-
m_hContext(other.m_hContext)
44+
m_hContext(NULL)
4545
{
4646
}
4747
//lint +e1554
@@ -57,7 +57,25 @@ ConsoleDialog::~ConsoleDialog()
5757
if (m_data)
5858
{
5959
delete m_data;
60+
m_data = NULL;
61+
}
62+
63+
if (m_hTabIcon)
64+
{
65+
::DestroyIcon(m_hTabIcon);
66+
m_hTabIcon = NULL;
6067
}
68+
69+
if (m_hContext)
70+
{
71+
::DestroyMenu(m_hContext);
72+
m_hContext = NULL;
73+
}
74+
75+
// To please Lint, let's NULL these handles and pointers
76+
m_hInput = NULL;
77+
m_console = NULL;
78+
6179
}
6280

6381

@@ -1025,19 +1043,23 @@ bool ConsoleDialog::parsePythonErrorLine(LineDetails *lineDetails)
10251043

10261044
void ConsoleDialog::onHotspotClick(SCNotification* notification)
10271045
{
1028-
int lineNumber = callScintilla(SCI_LINEFROMPOSITION, notification->position);
1029-
LineDetails lineDetails;
1030-
lineDetails.lineLength = (size_t)callScintilla(SCI_GETLINE, lineNumber);
1046+
assert(m_console != NULL);
1047+
if (m_console)
1048+
{
1049+
int lineNumber = callScintilla(SCI_LINEFROMPOSITION, notification->position);
1050+
LineDetails lineDetails;
1051+
lineDetails.lineLength = (size_t)callScintilla(SCI_GETLINE, lineNumber);
10311052

1032-
if (lineDetails.lineLength != SIZE_MAX)
1033-
{
1034-
lineDetails.line = new char[lineDetails.lineLength + 1];
1035-
callScintilla(SCI_GETLINE, lineNumber, reinterpret_cast<LPARAM>(lineDetails.line));
1036-
lineDetails.line[lineDetails.lineLength] = '\0';
1037-
if (parseLine(&lineDetails))
1038-
{
1039-
lineDetails.line[lineDetails.filenameEnd] = '\0';
1040-
m_console->openFile(lineDetails.line + lineDetails.filenameStart, lineDetails.errorLineNo);
1041-
}
1042-
}
1053+
if (lineDetails.lineLength != SIZE_MAX)
1054+
{
1055+
lineDetails.line = new char[lineDetails.lineLength + 1];
1056+
callScintilla(SCI_GETLINE, lineNumber, reinterpret_cast<LPARAM>(lineDetails.line));
1057+
lineDetails.line[lineDetails.lineLength] = '\0';
1058+
if (parseLine(&lineDetails))
1059+
{
1060+
lineDetails.line[lineDetails.filenameEnd] = '\0';
1061+
m_console->openFile(lineDetails.line + lineDetails.filenameStart, lineDetails.errorLineNo);
1062+
}
1063+
}
1064+
}
10431065
}

PythonScript/src/MenuManager.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ MenuManager::~MenuManager()
5959
{
6060
// I don't know what to do with that, but a destructor should never throw, so...
6161
}
62+
63+
if (m_pythonPluginMenu)
64+
{
65+
::DestroyMenu(m_pythonPluginMenu);
66+
m_pythonPluginMenu = NULL;
67+
}
68+
69+
if (m_hScriptsMenu)
70+
{
71+
::DestroyMenu(m_hScriptsMenu);
72+
m_hScriptsMenu = NULL;
73+
}
74+
75+
if (m_funcItems)
76+
{
77+
delete [] m_funcItems;
78+
m_funcItems = NULL;
79+
}
80+
81+
// To please Lint, let's NULL these handles and pointers
82+
m_hNotepad = NULL;
83+
m_hInst = NULL;
6284
}
6385

6486
MenuManager* MenuManager::getInstance()
@@ -579,6 +601,7 @@ FuncItem* MenuManager::getFuncItemArray(int *nbF, ItemVectorTD items, runScriptI
579601

580602
m_funcItemCount = (size_t)*nbF;
581603

604+
// WARNING: If getFuncItemArray is called twice, we'll leak memory!
582605
m_funcItems = new FuncItem[m_funcItemCount];
583606

584607
// Add all the static items passed in

PythonScript/src/NotepadPlusWrapper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ NotepadPlusWrapper::~NotepadPlusWrapper()
3535
{
3636
// I don't know what to do with that, but a destructor should never throw, so...
3737
}
38+
39+
// To please Lint, let's NULL these handles and pointers
40+
m_nppHandle = NULL;
41+
m_hInst = NULL;
3842
}
3943

4044
void NotepadPlusWrapper::notify(SCNotification *notifyCode)

PythonScript/src/PythonConsole.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ PythonConsole::PythonConsole(const PythonConsole& other) :
3737
m_pushFunc(other.m_pushFunc),
3838
m_sys(other.m_sys),
3939
mp_mainThreadState(other.mp_mainThreadState),
40-
m_statementRunning(other.m_statementRunning),
40+
m_statementRunning(CreateEvent(NULL, FALSE, TRUE, NULL)),
4141
m_hThread(other.m_hThread),
4242
m_hNotepad(other.m_hNotepad),
4343
m_consumerStarted(other.m_consumerStarted),
@@ -58,6 +58,16 @@ PythonConsole::~PythonConsole()
5858
{
5959
// I don't know what to do with that, but a destructor should never throw, so...
6060
}
61+
62+
if (m_statementRunning)
63+
{
64+
CloseHandle(m_statementRunning);
65+
m_statementRunning = NULL;
66+
}
67+
68+
// To please Lint, let's NULL these handles and pointers
69+
mp_mainThreadState = NULL;
70+
m_hNotepad = NULL;
6171
}
6272

6373
void PythonConsole::init(HINSTANCE hInst, NppData& nppData)

0 commit comments

Comments
 (0)