changeset 72:57ffd98dbe96

Fix race condition
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 01 Dec 2009 11:34:00 +0900
parents cba30013d8f5
children 02db4d794ccf
files freeDiameter/p_out.c
diffstat 1 files changed, 7 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/freeDiameter/p_out.c	Tue Dec 01 11:27:17 2009 +0900
+++ b/freeDiameter/p_out.c	Tue Dec 01 11:34:00 2009 +0900
@@ -65,24 +65,18 @@
 	
 	/* Create the message buffer */
 	CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz ));
+	pthread_cleanup_push( free, buf );
+	
+	/* Save a request before sending so that there is no race condition with the answer */
+	if (msg_is_a_req) {
+		CHECK_FCT_DO( ret = fd_p_sr_store(srl, msg, &hdr->msg_hbhid), { free(buf); return ret; } );
+	}
 	
 	/* Send the message */
-	pthread_cleanup_push( free, buf );
 	CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz), { free(buf); return ret; } );
 	pthread_cleanup_pop(1);
 	
-	/* Save a request */
-	if (msg_is_a_req) {
-		CHECK_FCT_DO( fd_p_sr_store(srl, msg, &hdr->msg_hbhid),
-			{
-				fd_log_debug("The following request was sent successfully but not saved locally:\n" );
-				fd_log_debug("	(as a result the matching answer will be discarded)\n" );
-				fd_msg_dump_walk(NONE, *msg);
-			} );
-				
-	}
-	
-	/* Free answers and unsaved requests */
+	/* Free remaining messages (i.e. answers) */
 	if (*msg) {
 		CHECK_FCT( fd_msg_free(*msg) );
 		*msg = NULL;
"Welcome to our mercurial repository"