From 2fce66b44cd20d5515beb3920d84926926347c91 Mon Sep 17 00:00:00 2001
From: scottmk <scottmk@9efc2488-bf62-4759-914b-345cdb29e865>
Date: Thu, 21 Jan 2010 01:08:37 +0000
Subject: [PATCH] Bug fix.

When all the servers for a given server go away, the router deletes the
server class from its internal data structures.  However that can happen
in the middle of a loop receiving successive messages from that server.

The old code would continue trying to read more messages from the
deleted server class, leading to a segfault.

The new code checks to see whether the server class still exists.  If
not, it breaks out of the loop.

M    src/router/osrf_router.c


git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1899 9efc2488-bf62-4759-914b-345cdb29e865
---
 src/router/osrf_router.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/router/osrf_router.c b/src/router/osrf_router.c
index ede2ee3..b048317 100644
--- a/src/router/osrf_router.c
+++ b/src/router/osrf_router.c
@@ -345,6 +345,12 @@ static void osrfRouterClassHandleIncoming( osrfRouter* router, const char* class
 
 					// A previous message bounced.  Try to send a clone of it to a
 					// different node of the same class.
+					
+					// First make a local copy of the class name.  If the class gets
+					// deleted, the classname parameter becomes invalid.
+					char classname_copy[ strlen( classname ) + 1 ];
+					strcpy( classname_copy, classname );
+
 					transport_message* bouncedMessage = osrfRouterClassHandleBounce(
 							router, classname, class, msg );
 					/* handle bounced message */
@@ -352,7 +358,12 @@ static void osrfRouterClassHandleIncoming( osrfRouter* router, const char* class
 						/* we have no one to send the requested message to */
 						message_free( msg );
 						osrfLogClearXid();
-						continue;
+						
+						// See if the class still exists
+						if( osrfHashGet( router->classes, classname_copy ) )
+							continue;   // It does; keep going
+						else
+							break;      // It doesn't; don't try to read from it any more
 					}
 					osrfRouterClassHandleMessage( router, class, bouncedMessage );
 					message_free( bouncedMessage );
-- 
2.11.0