Index: /trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp	(revision 49569)
+++ /trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp	(revision 49570)
@@ -519,4 +519,7 @@
  * a process B. Process B in turn then has a different guest PID.
  *
+ * Note: This also can happen when restoring from a saved state which
+ *       had a guest process running.
+ *
  * @return  IPRT status code.
  * @param   uPID                    PID to check.
@@ -524,24 +527,18 @@
 inline int GuestProcess::checkPID(uint32_t uPID)
 {
+    int rc = VINF_SUCCESS;
+
     /* Was there a PID assigned yet? */
     if (mData.mPID)
     {
-        /*
-
-         */
-        if (mSession->getProtocolVersion() < 2)
-        {
-            /* Simply ignore the stale requests. */
-            return (mData.mPID == uPID)
-                   ? VINF_SUCCESS : VERR_NOT_FOUND;
-        }
-#ifndef DEBUG_andy
-        /* This should never happen! */
-        AssertReleaseMsg(mData.mPID == uPID, ("Unterminated guest process (guest PID %RU32) sent data to a newly started process (host PID %RU32)\n",
-                                              uPID, mData.mPID));
-#endif
-    }
-
-    return VINF_SUCCESS;
+        if (RT_UNLIKELY(mData.mPID != uPID))
+        {
+            LogFlowFunc(("Stale guest process (PID=%RU32) sent data to a newly started process (pProcesS=%p, PID=%RU32, status=%RU32)\n",
+                         uPID, this, mData.mPID, mData.mStatus));
+            rc = VERR_NOT_FOUND;
+        }
+    }
+
+    return rc;
 }
 
@@ -865,6 +862,6 @@
 
 /**
- * Called by IGuestSession right before this process gets 
- * removed from the public process list. 
+ * Called by IGuestSession right before this process gets
+ * removed from the public process list.
  */
 int GuestProcess::onRemove(void)
@@ -876,5 +873,5 @@
     int vrc = VINF_SUCCESS;
 
-    /* 
+    /*
      * Note: The event source stuff holds references to this object,
      *       so make sure that this is cleaned up *before* calling uninit().
@@ -2060,6 +2057,6 @@
     int vrc = pSession->processCreateExInteral(mStartupInfo, pProcess);
     if (RT_SUCCESS(vrc))
-        vrc = fAsync 
-            ? pProcess->startProcessAsync() 
+        vrc = fAsync
+            ? pProcess->startProcessAsync()
             : pProcess->startProcess(30 * 1000 /* 30s timeout */, pGuestRc);
 
@@ -2164,17 +2161,14 @@
         /* Make sure the process runs until completion. */
         vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
-
-        Assert(RT_SUCCESS(guestRc));
-        guestRc = procTool.TerminatedOk(NULL /* Exit code */);
-        if (RT_FAILURE(guestRc))
-            vrc = VERR_GSTCTL_GUEST_ERROR;                        
-        if (pGuestRc)
-            *pGuestRc = guestRc;
-    }
-    else if (vrc == VERR_GSTCTL_GUEST_ERROR)
-    {
-        if (pGuestRc)
-            *pGuestRc = guestRc;
-    }
+        if (RT_SUCCESS(vrc))
+        {
+            guestRc = procTool.TerminatedOk(NULL /* Exit code */);
+            if (RT_FAILURE(guestRc))
+                vrc = VERR_GSTCTL_GUEST_ERROR;
+        }
+    }
+
+    if (pGuestRc)
+        *pGuestRc = guestRc;
 
     LogFlowFunc(("Returned rc=%Rrc, guestRc=%Rrc\n", vrc, guestRc));
@@ -2322,5 +2316,5 @@
 
             default:
-                AssertReleaseMsgFailed(("Unhandled process wait result %RU32\n", waitRes));
+                AssertMsgFailed(("Unhandled process wait result %RU32\n", waitRes));
                 break;
         }
Index: /trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp	(revision 49569)
+++ /trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp	(revision 49570)
@@ -283,5 +283,5 @@
 
 #ifdef VBOX_WITH_GUEST_CONTROL
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
     LogFlowThisFunc(("Closing directories (%zu total)\n",
@@ -321,5 +321,5 @@
     mData.mProcesses.clear();
 
-    AssertMsg(mData.mNumObjects == 0, 
+    AssertMsg(mData.mNumObjects == 0,
               ("mNumObjects=%RU32 when it should be 0\n", mData.mNumObjects));
 
@@ -731,5 +731,5 @@
                 vrc = VERR_INVALID_PARAMETER;
         }
-        
+
         if (uMode)
         {
@@ -808,5 +808,5 @@
             LogFlowFunc(("Removing directory \"%s\" (Session: %RU32) (now total %zu processes, %ld objects)\n",
                          Utf8Str(strName).c_str(), mData.mSession.mID, mData.mDirectories.size() - 1, mData.mNumObjects - 1));
- 
+
             rc = pDirectory->onRemove();
             mData.mDirectories.erase(itDirs);
@@ -1194,5 +1194,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    int rc = VERR_NOT_FOUND;    
+    int rc = VERR_NOT_FOUND;
 
     SessionFiles::iterator itFiles = mData.mFiles.begin();
@@ -1221,5 +1221,5 @@
             fireGuestFileRegisteredEvent(mEventSource, this, pCurFile,
                                          false /* Unregistered */);
-            pCurFile.setNull();            
+            pCurFile.setNull();
             break;
         }
@@ -1229,5 +1229,5 @@
 
     LogFlowFuncLeaveRC(rc);
-    return rc;    
+    return rc;
 }
 
@@ -1426,5 +1426,6 @@
     }
 
-    LogFlowFuncLeaveRC(vrc);
+    LogFlowThisFunc(("Returning rc=%Rrc, guestRc=%Rrc\n",
+                     vrc, guestRc));
     return vrc;
 }
@@ -1515,6 +1516,6 @@
 
 /**
- * Called by IGuest right before this session gets removed from 
- * the public session list. 
+ * Called by IGuest right before this session gets removed from
+ * the public session list.
  */
 int GuestSession::onRemove(void)
@@ -1526,5 +1527,5 @@
     int vrc = VINF_SUCCESS;
 
-    /* 
+    /*
      * Note: The event source stuff holds references to this object,
      *       so make sure that this is cleaned up *before* calling uninit.
