Fix a crash problem which can happen when RTSP register/deregister.
The cause was that the RTSPClientConnection instance had been deleted in handleRequestBytes when the task of register/deregister was continued.
Index: live/liveMedia/RTSPServer.cpp
===================================================================
--- live.orig/liveMedia/RTSPServer.cpp
+++ live/liveMedia/RTSPServer.cpp
@@ -272,7 +272,7 @@ RTSPServer::RTSPClientConnection
 ::RTSPClientConnection(RTSPServer& ourServer, int clientSocket, struct sockaddr_in clientAddr)
   : GenericMediaServer::ClientConnection(ourServer, clientSocket, clientAddr),
     fOurRTSPServer(ourServer), fClientInputSocket(fOurSocket), fClientOutputSocket(fOurSocket),
-    fIsActive(True), fRecursionCount(0), fOurSessionCookie(NULL) {
+    fIsActive(True), fRecursionCount(0), fOurSessionCookie(NULL), fScheduledDelayedTask(0) {
   resetRequestBuffer();
 }
 
@@ -886,7 +886,8 @@ void RTSPServer::RTSPClientConnection::h
   } while (numBytesRemaining > 0);
   
   --fRecursionCount;
-  if (!fIsActive) {
+  // If it has a scheduledDelayedTask, don't delete the instance or close the sockets. The sockets can be reused in the task.
+  if (!fIsActive && fScheduledDelayedTask <= 0) {
     if (fRecursionCount > 0) closeSockets(); else delete this;
     // Note: The "fRecursionCount" test is for a pathological situation where we reenter the event loop and get called recursively
     // while handling a command (e.g., while handling a "DESCRIBE", to get a SDP description).
Index: live/liveMedia/RTSPServerRegister.cpp
===================================================================
--- live.orig/liveMedia/RTSPServerRegister.cpp
+++ live/liveMedia/RTSPServerRegister.cpp
@@ -240,6 +240,7 @@ void RTSPServer
     ParamsForREGISTER* registerParams = new ParamsForREGISTER(cmd, this, url, urlSuffix, reuseConnection, deliverViaTCP, proxyURLSuffix);
     envir().taskScheduler().scheduleDelayedTask(reuseConnection ? DELAY_USECS_AFTER_REGISTER_RESPONSE : 0,
 						(TaskFunc*)continueHandlingREGISTER, registerParams);
+    ++fScheduledDelayedTask;
   } else if (responseStr != NULL) {
     setRTSPResponse(responseStr);
     delete[] responseStr;
@@ -294,6 +295,7 @@ void RTSPServer::RTSPClientConnection::c
 }
 
 void RTSPServer::RTSPClientConnection::continueHandlingREGISTER1(ParamsForREGISTER* params) {
+  --fScheduledDelayedTask;
   // Reuse our socket if requested:
   int socketNumToBackEndServer = params->fReuseConnection ? fClientOutputSocket : -1;
 
@@ -305,6 +307,8 @@ void RTSPServer::RTSPClientConnection::c
     // deleting this.
     fClientInputSocket = fClientOutputSocket = -1; // so the socket doesn't get closed when we get deleted
     delete this;
+  } else if (!fIsActive && fRecursionCount <= 0 && fScheduledDelayedTask <= 0) {
+	  delete this;
   }
   
   ourServer->implementCmd_REGISTER(params->fCmd,
Index: live/liveMedia/include/RTSPServer.hh
===================================================================
--- live.orig/liveMedia/include/RTSPServer.hh
+++ live/liveMedia/include/RTSPServer.hh
@@ -214,6 +214,7 @@ public: // should be protected, but some
     Authenticator fCurrentAuthenticator; // used if access control is needed
     char* fOurSessionCookie; // used for optional RTSP-over-HTTP tunneling
     unsigned fBase64RemainderCount; // used for optional RTSP-over-HTTP tunneling (possible values: 0,1,2,3)
+    unsigned fScheduledDelayedTask;
   };
 
   // The state of an individual client session (using one or more sequential TCP connections) handled by a RTSP server:
