浏览代码

fix crash on client reset

David Rose 22 年之前
父节点
当前提交
19364486e7
共有 2 个文件被更改,包括 16 次插入7 次删除
  1. 14 6
      pandatool/src/pstatserver/pStatServer.cxx
  2. 2 1
      pandatool/src/pstatserver/pStatServer.h

+ 14 - 6
pandatool/src/pstatserver/pStatServer.cxx

@@ -114,10 +114,18 @@ poll() {
 
   _listener->poll();
 
-  Readers::const_iterator ri;
-  for (ri = _readers.begin(); ri != _readers.end(); ++ri) {
-    (*ri).second->poll();
-    (*ri).second->idle();
+  Readers::const_iterator ri = _readers.begin();
+  while (ri != _readers.end()) {
+    // Preincrement the iterator, in case we remove it as a result of
+    // calling poll().
+    Readers::const_iterator rnext = ri;
+    ++rnext;
+    PStatReader *reader = (*ri).second;
+
+    reader->poll();
+    reader->idle();
+    
+    ri = rnext;
   }
 }
 
@@ -224,7 +232,7 @@ is_thread_safe() {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: PStatServer::connection_reset
-//       Access: Private
+//       Access: Protected, Virtual
 //  Description: Called when a lost connection is detected by the net
 //               code, this should pass the word on to the interested
 //               parties and clean up gracefully.
@@ -243,7 +251,7 @@ connection_reset(const PT(Connection) &connection, PRErrorCode errcode) {
 
     // Unfortunately, we can't delete the reader right away, because
     // we might have been called from a method on the reader!  We'll
-    // have to safe the reader pointer and delete it some time later.
+    // have to save the reader pointer and delete it some time later.
     _lost_readers.push_back(reader);
   }
 }

+ 2 - 1
pandatool/src/pstatserver/pStatServer.h

@@ -63,10 +63,11 @@ public:
 
   virtual bool is_thread_safe();
 
-private:
+protected:
   virtual void connection_reset(const PT(Connection) &connection, 
                                 PRErrorCode errcode);
 
+private:
   PStatListener *_listener;
 
   typedef pmap<PT(Connection), PStatReader *> Readers;