]> git.saurik.com Git - wxWidgets.git/commitdiff
really ensure that the pointer returned from MyConnection::OnRequest() remains valid
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 17 Nov 2008 11:00:32 +0000 (11:00 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 17 Nov 2008 11:00:32 +0000 (11:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56816 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/ipc/server.cpp
samples/ipc/server.h

index afe890aacf80977ba0834e5befd6217a725a4a39..4bd26352a2b5f14a8cd6f378e0b5fba0764349c0 100644 (file)
@@ -324,25 +324,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 +353,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;
 }
index 23959382ff2a3ee59e698a1649a59d1756291cec..a81a4421cc98c5e3b7cbc04d4c6b4dd83d24a874 100644 (file)
@@ -78,9 +78,9 @@ public:
     wxString m_advise;
 
 protected:
-    // the data returned by last OnRequest(): we keep it in this wxString to
+    // the data returned by last OnRequest(): we keep it in this buffer to
     // ensure that the pointer we return from OnRequest() stays valid
-    wxString m_requestData;
+    wxCharBuffer m_requestData;
 };
 
 class MyServer : public wxServer