Fix #1248: segfault in shell module.

It happened when client disconnects.
This commit is contained in:
Alexey Sokolov
2016-03-04 08:04:03 +00:00
parent 9b31a077a5
commit 2fdbe51df5
2 changed files with 47 additions and 13 deletions

View File

@@ -49,6 +49,9 @@ class CShellSock : public CExecSock {
void ReadLine(const CString& sData) override;
void Disconnected() override;
bool IsOfClient(CClient* pClient) const { return pClient == m_pClient; }
bool IsOfModule(CShellMod* pParent) const { return pParent == m_pParent; }
CShellMod* m_pParent;
private:
@@ -117,6 +120,21 @@ class CShellMod : public CModule {
"SHELL");
}
void OnClientDisconnect() override {
std::vector<Csock*> vDeadCommands;
for (Csock* pSock : *GetManager()) {
if (CShellSock* pSSock = dynamic_cast<CShellSock*>(pSock)) {
if (pSSock->IsOfModule(this) &&
pSSock->IsOfClient(GetClient())) {
vDeadCommands.push_back(pSock);
}
}
}
for (Csock* pSock : vDeadCommands) {
GetManager()->DelSockByAddr(pSock);
}
}
private:
CString m_sPath;
};