Skip to content

Commit 84df8be

Browse files
committed
XmlRpcEmbedder: clean up more gracefully (i.e. cancel jobs before deleting objects) if the XmlRpcPipeServer terminates unexpectedly
1 parent d0e9734 commit 84df8be

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

XmlRpcEmbedder/xmlrpc_embedder.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,17 @@ XmlRpcInstance::~XmlRpcInstance()
347347
delete m_client;
348348
if(m_pipeclient)
349349
delete m_pipeclient;
350-
m_client=NULL;
351-
m_pipeclient=NULL;
350+
m_client=0;
351+
m_pipeclient=0;
352352
}
353353

354354
XmlRpcInstance::XmlRpcInstance(const wxString &processcmd, int port, const wxString &hostaddress, wxWindow *parent)
355355
{
356356
m_parent=parent;
357357
m_port=port;
358-
m_proc=NULL;
359-
m_client=NULL;
360-
m_pipeclient=NULL;
358+
m_proc=0;
359+
m_client=0;
360+
m_pipeclient=0;
361361
m_proc_dead=true;
362362
m_hostaddress=hostaddress;
363363
m_paused=false;
@@ -437,18 +437,29 @@ bool XmlRpcInstance::ExecAsync(const wxString &method, const XmlRpc::XmlRpcValue
437437
return AddJob(new ExecAsyncJob(this,method,inarg,hndlr,id));
438438
}
439439

440+
void XmlRpcInstance::CleanupTerminatedProcess()
441+
{
442+
if(m_proc!=0)
443+
{
444+
ClearJobs();
445+
delete m_proc;
446+
m_proc=0;
447+
m_proc_id=-1;
448+
m_proc_killlevel=0;
449+
}
450+
}
451+
440452
void XmlRpcInstance::OnEndProcess(wxProcessEvent &event)
441453
{
442454
// std::cout<<"PYCC: PROCESS DIED!!"<<std::endl;
443455
//TODO: m_exitcode=event.GetExitCode();
444456
m_proc_dead=true;
445-
delete m_proc;
446-
m_proc=NULL;
447-
m_proc_id=-1;
448-
m_proc_killlevel=0;
449457
wxCommandEvent ce(wxEVT_XMLRPC_PROC_END,0);
450458
if(m_parent)
451459
m_parent->AddPendingEvent(ce);
460+
if(m_jobrunning)
461+
return;
462+
CleanupTerminatedProcess();
452463
// XmlRpcMgr::Get().Remove(this);
453464
}
454465

@@ -557,6 +568,8 @@ void XmlRpcInstance::OnJobNotify(wxCommandEvent &event)
557568
}
558569
if(m_paused)
559570
return;
571+
if(m_proc_dead)
572+
CleanupTerminatedProcess();
560573
NextJob();
561574
}
562575

XmlRpcEmbedder/xmlrpc_embedder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class XmlRpcInstance: public wxEvtHandler
105105
// Retrieves the next threaded job from the queue and starts it
106106
bool NextJob();
107107
private:
108+
// Deletes process object and empties queue
109+
void CleanupTerminatedProcess();
108110
// Called by the constructor to actually start the process running
109111
long LaunchProcess(const wxString &processcmd);
110112
wxWindow *m_parent;

0 commit comments

Comments
 (0)