Commit 1256df11 authored by Milian Wolff's avatar Milian Wolff
Browse files

Don't leak the debug sessions

Fixes various memory leaks reported in the test_midbus test.
The m_shuttingDown member is required as IDebugSession::raiseEvent
would otherwise call pure-virtuals when the class is already
partially destroyed.
parent 9196bb7d
......@@ -29,8 +29,9 @@ public:
QString m_addr;
};
IDebugSession::IDebugSession()
: d_ptr(new IDebugSessionPrivate(this))
IDebugSession::IDebugSession(QObject* parent)
: QObject(parent)
, d_ptr(new IDebugSessionPrivate(this))
{
connect(this, &IDebugSession::stateChanged,
this, [this](IDebugSession::DebuggerState state) { Q_D(IDebugSession); d->slotStateChanged(state); });
......
......@@ -25,7 +25,7 @@ class KDEVPLATFORMDEBUGGER_EXPORT IDebugSession : public QObject
{
Q_OBJECT
public:
IDebugSession();
IDebugSession(QObject* parent = nullptr);
~IDebugSession() override;
enum DebuggerState {
......
......@@ -50,10 +50,11 @@ namespace {
constexpr DBGStateFlags notStartedDebuggerFlags{s_dbgNotStarted | s_appNotStarted};
}
MIDebugSession::MIDebugSession(MIDebuggerPlugin *plugin)
: m_procLineMaker(new ProcessLineMaker(this))
MIDebugSession::MIDebugSession(MIDebuggerPlugin* plugin)
: KDevelop::IDebugSession(plugin)
, m_procLineMaker(new ProcessLineMaker(this))
, m_commandQueue(new CommandQueue)
, m_debuggerState{notStartedDebuggerFlags}
, m_debuggerState { notStartedDebuggerFlags }
, m_tty(nullptr)
, m_plugin(plugin)
{
......@@ -80,7 +81,10 @@ MIDebugSession::MIDebugSession(MIDebuggerPlugin *plugin)
MIDebugSession::~MIDebugSession()
{
m_shuttingDown = true;
qCDebug(DEBUGGERCOMMON) << "Destroying MIDebugSession";
// Deleting the session involves shutting down gdb nicely.
// When were attached to a process, we must first detach so that the process
// can continue running as it was before being attached. gdb is quite slow to
......@@ -894,7 +898,9 @@ void MIDebugSession::raiseEvent(event_t e)
qCDebug(DEBUGGERCOMMON) << "State reload in progress\n";
}
IDebugSession::raiseEvent(e);
if (!m_shuttingDown) {
IDebugSession::raiseEvent(e);
}
if (e == program_state_changed) {
m_stateReloadInProgress = false;
......
......@@ -332,6 +332,7 @@ protected:
bool m_stateReloadInProgress = false;
bool m_stateReloadNeeded = false;
bool m_shuttingDown = false;
std::unique_ptr<STTY> m_tty;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment