X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/589c1174f4dd9ccd5b7fc941e3d239888e1a8653..8a31648287be0ef976f133de2786b137f1e98340:/samples/ipc/server.cpp diff --git a/samples/ipc/server.cpp b/samples/ipc/server.cpp index afe890aacf..26b09f6791 100644 --- a/samples/ipc/server.cpp +++ b/samples/ipc/server.cpp @@ -160,11 +160,7 @@ void MyFrame::UpdateUI() void MyFrame::OnClose(wxCloseEvent& event) { - if (m_server) - { - delete m_server; - m_server = NULL; - } + wxDELETE(m_server); event.Skip(); } @@ -185,8 +181,7 @@ void MyFrame::OnStart(wxCommandEvent& WXUNUSED(event)) else { wxLogMessage("Server %s failed to start", servername); - delete m_server; - m_server = NULL; + wxDELETE(m_server); } UpdateUI(); } @@ -262,8 +257,7 @@ void MyServer::Disconnect() { if ( m_connection ) { - delete m_connection; - m_connection = NULL; + wxDELETE(m_connection); wxGetApp().GetFrame()->UpdateUI(); wxLogMessage("Disconnected client"); } @@ -324,25 +318,26 @@ MyConnection::OnRequest(const wxString& topic, { *size = 0; - wxString afterDate; + wxString s, + afterDate; if ( item.StartsWith("Date", &afterDate) ) { const wxDateTime now = wxDateTime::Now(); if ( afterDate.empty() ) { - m_requestData = now.Format(); + s = now.Format(); *size = wxNO_LEN; } else if ( afterDate == "+len" ) { - m_requestData = now.FormatTime() + " " + now.FormatDate(); - *size = strlen(m_requestData.mb_str()) + 1; + s = now.FormatTime() + " " + now.FormatDate(); + *size = strlen(s.mb_str()) + 1; } } else if ( item == "bytes[3]" ) { - m_requestData = "123"; + s = "123"; *size = 3; } @@ -352,7 +347,10 @@ MyConnection::OnRequest(const wxString& topic, return NULL; } - const void * const data = m_requestData.mb_str(); + // store the data pointer to which we return in a member variable to ensure + // that the pointer remains valid even after we return + m_requestData = s.mb_str(); + const void * const data = m_requestData; Log("OnRequest", topic, item, data, *size, format); return data; }