Index: libfdcore/fdd.y
===================================================================
--- libfdcore/fdd.y	(revision 961)
+++ libfdcore/fdd.y	(revision 964)
@@ -328,9 +328,8 @@
 				if (fd == NULL) {
 					int ret = errno;
-					TRACE_DEBUG_ERROR("Unable to open extension file %s for reading: %s\n", fname, strerror(ret));
-					yyerror (&yylloc, conf, "Error adding extension"); 
-					YYERROR;
-				}
-				fclose(fd);
+					TRACE_DEBUG_ERROR("WARNING: Unable to open extension file %s for reading: %s\nLD_LIBRARY_PATH will be used.\n", fname, strerror(ret));
+				} else {
+					fclose(fd);
+				}
 				
 				/* Try and open the configuration file (optional) */
Index: libfdcore/p_ce.c
===================================================================
--- libfdcore/p_ce.c	(revision 837)
+++ libfdcore/p_ce.c	(revision 935)
@@ -455,8 +455,8 @@
 				{
 					struct avp * inavp = NULL;
-					application_id_t aid = 0;
 					vendor_id_t vid = 0;
-					int auth = 0;
-					int acct = 0;
+					application_id_t auth_aid = 0;
+					application_id_t acct_aid = 0;
+					int invalid=0;
 
 					/* get the first child AVP */
@@ -482,15 +482,35 @@
 						switch (inhdr->avp_code) {
 							case AC_VENDOR_ID: /* Vendor-Id */
+								if (vid != 0)
+									invalid++; /* We already had one such AVP */
 								vid = inhdr->avp_value->u32;
 								break;
 							case AC_AUTH_APPLICATION_ID: /* Auth-Application-Id */
-								aid = inhdr->avp_value->u32;
-								auth += 1;
+								if (auth_aid != 0)
+									invalid++; /* We already had one such AVP */
+#ifndef WORKAROUND_ACCEPT_INVALID_VSAI
+								if (acct_aid != 0)
+									invalid++; /* Only 1 *-Application-Id AVP is allowed */
+#endif /* WORKAROUND_ACCEPT_INVALID_VSAI */
+								auth_aid = inhdr->avp_value->u32;
 								break;
 							case AC_ACCT_APPLICATION_ID: /* Acct-Application-Id */
-								aid = inhdr->avp_value->u32;
-								acct += 1;
+								if (acct_aid != 0)
+									invalid++; /* We already had one such AVP */
+#ifndef WORKAROUND_ACCEPT_INVALID_VSAI
+								if (auth_aid != 0)
+									invalid++; /* Only 1 *-Application-Id AVP is allowed */
+#endif /* WORKAROUND_ACCEPT_INVALID_VSAI */
+								acct_aid = inhdr->avp_value->u32;
 								break;
 							/* ignore other AVPs */
+						}
+						
+						if (invalid) {
+							TRACE_DEBUG(FULL, "Invalid Vendor-Specific-Application-Id AVP received, ignored");
+							fd_msg_dump_one(FULL, avp);
+							error->pei_errcode = "DIAMETER_INVALID_AVP_VALUE";
+							error->pei_avp = avp;
+							return EINVAL;
 						}
 
@@ -500,13 +520,10 @@
 					}
 					
-					if (auth + acct != 1) {
-						TRACE_DEBUG(FULL, "Invalid Vendor-Specific-Application-Id AVP received, ignored");
-						fd_msg_dump_one(FULL, avp);
-						error->pei_errcode = "DIAMETER_INVALID_AVP_VALUE";
-						error->pei_avp = avp;
-						return EINVAL;
-					} else {
-						/* Add an entry in the list */
-						CHECK_FCT( fd_app_merge(&peer->p_hdr.info.runtime.pir_apps, aid, vid, auth, acct) );
+					/* Add entry in the list */
+					if (auth_aid) {
+						CHECK_FCT( fd_app_merge(&peer->p_hdr.info.runtime.pir_apps, auth_aid, vid, 1, 0) );
+					}
+					if (acct_aid) {
+						CHECK_FCT( fd_app_merge(&peer->p_hdr.info.runtime.pir_apps, acct_aid, vid, 0, 1) );
 					}
 				}
Index: libfdcore/routing_dispatch.c
===================================================================
--- libfdcore/routing_dispatch.c	(revision 754)
+++ libfdcore/routing_dispatch.c	(revision 934)
@@ -424,5 +424,5 @@
 
 /* The DISPATCH message processing */
-static int msg_dispatch(struct msg ** pmsg)
+static int msg_dispatch(struct msg * msg)
 {
 	struct msg_hdr * hdr;
@@ -432,7 +432,8 @@
 	char * ec = NULL;
 	char * em = NULL;
+	struct msg *msgptr = msg;
 
 	/* Read the message header */
-	CHECK_FCT( fd_msg_hdr(*pmsg, &hdr) );
+	CHECK_FCT( fd_msg_hdr(msg, &hdr) );
 	is_req = hdr->msg_flags & CMD_FLAG_REQUEST;
 	
@@ -441,15 +442,14 @@
 
 	/* At this point, we need to understand the message content, so parse it */
-	CHECK_FCT_DO( ret = fd_msg_parse_or_error( pmsg ),
+	CHECK_FCT_DO( ret = fd_msg_parse_or_error( &msgptr ),
 		{
 			/* in case of error */
-			if ((ret == EBADMSG) && (*pmsg != NULL)) {
-				/* msg now contains the answer message to send back */
-				CHECK_FCT( fd_fifo_post(fd_g_outgoing, pmsg) );
-			}
-			if (*pmsg) {	/* another error happen'd */
-				fd_msg_log( FD_MSG_LOG_DROPPED, *pmsg,  "An unexpected error occurred while parsing the message (%s)", strerror(ret));
-				CHECK_FCT_DO( fd_msg_free(*pmsg), /* continue */);
-				*pmsg = NULL;
+			if ((ret == EBADMSG) && (msgptr != NULL)) {
+				/* msgptr now contains the answer message to send back */
+				CHECK_FCT( fd_fifo_post(fd_g_outgoing, &msgptr) );
+			}
+			if (msgptr) {	/* another error happen'd */
+				fd_msg_log( FD_MSG_LOG_DROPPED, msgptr,  "An unexpected error occurred while parsing the message (%s)", strerror(ret));
+				CHECK_FCT_DO( fd_msg_free(msgptr), /* continue */);
 			}
 			/* We're done with this one */
@@ -464,5 +464,5 @@
 
 		/* Retrieve the corresponding query */
-		CHECK_FCT( fd_msg_answ_getq( *pmsg, &qry ) );
+		CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) );
 
 		/* Retrieve any registered handler */
@@ -473,21 +473,23 @@
 
 			TRACE_DEBUG(FULL, "Calling callback registered when query was sent (%p, %p)", anscb, data);
-			(*anscb)(data, pmsg);
+			(*anscb)(data, &msgptr);
 			
 			/* If the message is processed, we're done */
-			if (*pmsg == NULL) {
+			if (msgptr == NULL) {
 				return 0;
 			}
+			
+			/* otherwise continue the dispatching --hoping that the anscb callback did not mess with our message :) */
 		}
 	}
 	
 	/* Retrieve the session of the message */
-	CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *pmsg, &sess, NULL) );
+	CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, msgptr, &sess, NULL) );
 
 	/* Now, call any callback registered for the message */
-	CHECK_FCT( fd_msg_dispatch ( pmsg, sess, &action, &ec) );
+	CHECK_FCT( fd_msg_dispatch ( &msgptr, sess, &action, &ec) );
 
 	/* Now, act depending on msg and action and ec */
-	if (*pmsg)
+	if (msgptr) {
 		switch ( action ) {
 			case DISP_ACT_CONT:
@@ -495,5 +497,5 @@
 				if (!fd_g_config->cnf_flags.no_fwd) {
 					/* requeue to fd_g_outgoing */
-					CHECK_FCT( fd_fifo_post(fd_g_outgoing, pmsg) );
+					CHECK_FCT( fd_fifo_post(fd_g_outgoing, &msgptr) );
 					break;
 				}
@@ -509,18 +511,18 @@
 				
 				if (!is_req) {
-					fd_msg_log( FD_MSG_LOG_DROPPED, *pmsg,  "Internal error: Answer received to locally issued request, but not handled by any handler.");
-					fd_msg_free(*pmsg);
-					*pmsg = NULL;
+					fd_msg_log( FD_MSG_LOG_DROPPED, msgptr,  "Internal error: Answer received to locally issued request, but not handled by any handler.");
+					fd_msg_free(msgptr);
 					break;
 				}
 				
 				/* Create an answer with the error code and message */
-				CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, pmsg, 0 ) );
-				CHECK_FCT( fd_msg_rescode_set(*pmsg, ec, em, NULL, 1 ) );
+				CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, &msgptr, 0 ) );
+				CHECK_FCT( fd_msg_rescode_set(msgptr, ec, em, NULL, 1 ) );
 				
 			case DISP_ACT_SEND:
 				/* Now, send the message */
-				CHECK_FCT( fd_fifo_post(fd_g_outgoing, pmsg) );
-		}
+				CHECK_FCT( fd_fifo_post(fd_g_outgoing, &msgptr) );
+		}
+	}
 	
 	/* We're done with dispatching this message */
@@ -529,5 +531,5 @@
 
 /* The ROUTING-IN message processing */
-static int msg_rt_in(struct msg ** pmsg)
+static int msg_rt_in(struct msg * msg)
 {
 	struct msg_hdr * hdr;
@@ -536,7 +538,8 @@
 	DiamId_t qry_src = NULL;
 	size_t   qry_src_len = 0;
+	struct msg *msgptr = msg;
 
 	/* Read the message header */
-	CHECK_FCT( fd_msg_hdr(*pmsg, &hdr) );
+	CHECK_FCT( fd_msg_hdr(msg, &hdr) );
 	is_req = hdr->msg_flags & CMD_FLAG_REQUEST;
 	is_err = hdr->msg_flags & CMD_FLAG_ERROR;
@@ -544,5 +547,5 @@
 	/* Handle incorrect bits */
 	if (is_req && is_err) {
-		CHECK_FCT( return_error( pmsg, "DIAMETER_INVALID_HDR_BITS", "R & E bits were set", NULL) );
+		CHECK_FCT( return_error( &msgptr, "DIAMETER_INVALID_HDR_BITS", "R & E bits were set", NULL) );
 		return 0;
 	}
@@ -564,5 +567,5 @@
 			TRACE_DEBUG(INFO, "Received a routable message with application id 0 or " _stringize(AI_RELAY) " (relay),\n"
 					  " returning DIAMETER_APPLICATION_UNSUPPORTED");
-			CHECK_FCT( return_error( pmsg, "DIAMETER_APPLICATION_UNSUPPORTED", "Routable message with application id 0 or relay", NULL) );
+			CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", "Routable message with application id 0 or relay", NULL) );
 			return 0;
 		} else {
@@ -573,5 +576,5 @@
 
 		/* Parse the message for Dest-Host and Dest-Realm */
-		CHECK_FCT(  fd_msg_browse(*pmsg, MSG_BRW_FIRST_CHILD, &avp, NULL)  );
+		CHECK_FCT(  fd_msg_browse(msgptr, MSG_BRW_FIRST_CHILD, &avp, NULL)  );
 		while (avp) {
 			struct avp_hdr * ahdr;
@@ -590,5 +593,5 @@
 							{
 								if (error_info.pei_errcode) {
-									CHECK_FCT( return_error( pmsg, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
+									CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
 									return 0;
 								} else {
@@ -610,5 +613,5 @@
 							{
 								if (error_info.pei_errcode) {
-									CHECK_FCT( return_error( pmsg, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
+									CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
 									return 0;
 								} else {
@@ -632,5 +635,5 @@
 							{
 								if (error_info.pei_errcode) {
-									CHECK_FCT( return_error( pmsg, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
+									CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
 									return 0;
 								} else {
@@ -657,5 +660,5 @@
 		/* Handle the missing routing AVPs first */
 		if ( is_dest_realm == UNKNOWN ) {
-			CHECK_FCT( return_error( pmsg, "DIAMETER_COMMAND_UNSUPPORTED", "Non-routable message not supported (invalid bit ? missing Destination-Realm ?)", NULL) );
+			CHECK_FCT( return_error( &msgptr, "DIAMETER_COMMAND_UNSUPPORTED", "Non-routable message not supported (invalid bit ? missing Destination-Realm ?)", NULL) );
 			return 0;
 		}
@@ -665,8 +668,8 @@
 			if (is_local_app == YES) {
 				/* Ok, give the message to the dispatch thread */
-				CHECK_FCT( fd_fifo_post(fd_g_local, pmsg) );
+				CHECK_FCT( fd_fifo_post(fd_g_local, &msgptr) );
 			} else {
 				/* We don't support the application, reply an error */
-				CHECK_FCT( return_error( pmsg, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) );
+				CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) );
 			}
 			return 0;
@@ -676,5 +679,5 @@
 		if ((is_dest_host == NO) || (is_dest_realm == NO)) {
 			if (fd_g_config->cnf_flags.no_fwd) {
-				CHECK_FCT( return_error( pmsg, "DIAMETER_UNABLE_TO_DELIVER", "I am not a Diameter agent", NULL) );
+				CHECK_FCT( return_error( &msgptr, "DIAMETER_UNABLE_TO_DELIVER", "I am not a Diameter agent", NULL) );
 				return 0;
 			}
@@ -689,5 +692,5 @@
 					{
 						/* If the process failed, we assume it is because of the AVP format */
-						CHECK_FCT( return_error( pmsg, "DIAMETER_INVALID_AVP_VALUE", "Failed to process decorated NAI", un) );
+						CHECK_FCT( return_error( &msgptr, "DIAMETER_INVALID_AVP_VALUE", "Failed to process decorated NAI", un) );
 						return 0;
 					} );
@@ -696,5 +699,5 @@
 			if (is_nai) {
 				/* We have transformed the AVP, now submit it again in the queue */
-				CHECK_FCT(fd_fifo_post(fd_g_incoming, pmsg) );
+				CHECK_FCT(fd_fifo_post(fd_g_incoming, &msgptr) );
 				return 0;
 			}
@@ -702,5 +705,5 @@
 			if (is_local_app == YES) {
 				/* Handle localy since we are able to */
-				CHECK_FCT(fd_fifo_post(fd_g_local, pmsg) );
+				CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) );
 				return 0;
 			}
@@ -708,5 +711,5 @@
 			if (fd_g_config->cnf_flags.no_fwd) {
 				/* We return an error */
-				CHECK_FCT( return_error( pmsg, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) );
+				CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) );
 				return 0;
 			}
@@ -720,10 +723,10 @@
 
 		/* Retrieve the corresponding query and its origin */
-		CHECK_FCT( fd_msg_answ_getq( *pmsg, &qry ) );
+		CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) );
 		CHECK_FCT( fd_msg_source_get( qry, &qry_src, &qry_src_len ) );
 
 		if ((!qry_src) && (!is_err)) {
 			/* The message is a normal answer to a request issued localy, we do not call the callbacks chain on it. */
-			CHECK_FCT(fd_fifo_post(fd_g_local, pmsg) );
+			CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) );
 			return 0;
 		}
@@ -740,5 +743,5 @@
 
 		/* requests: dir = 1 & 2 => in order; answers = 3 & 2 => in reverse order */
-		for (	li = (is_req ? rt_fwd_list.next : rt_fwd_list.prev) ; *pmsg && (li != &rt_fwd_list) ; li = (is_req ? li->next : li->prev) ) {
+		for (	li = (is_req ? rt_fwd_list.next : rt_fwd_list.prev) ; msgptr && (li != &rt_fwd_list) ; li = (is_req ? li->next : li->prev) ) {
 			struct rt_hdl * rh = (struct rt_hdl *)li;
 			int ret;
@@ -750,10 +753,10 @@
 
 			/* Ok, call this cb */
-			TRACE_DEBUG(ANNOYING, "Calling next FWD callback on %p : %p", *pmsg, rh->rt_fwd_cb);
-			CHECK_FCT_DO( ret = (*rh->rt_fwd_cb)(rh->cbdata, pmsg),
+			TRACE_DEBUG(ANNOYING, "Calling next FWD callback on %p : %p", msgptr, rh->rt_fwd_cb);
+			CHECK_FCT_DO( ret = (*rh->rt_fwd_cb)(rh->cbdata, &msgptr),
 				{
-					fd_msg_log( FD_MSG_LOG_DROPPED, *pmsg, "Internal error: a FWD routing callback returned an error (%s)", strerror(ret));
-					fd_msg_free(*pmsg);
-					*pmsg = NULL;
+					fd_msg_log( FD_MSG_LOG_DROPPED, msgptr, "Internal error: a FWD routing callback returned an error (%s)", strerror(ret));
+					fd_msg_free(msgptr);
+					msgptr = NULL;
 				} );
 		}
@@ -763,5 +766,5 @@
 
 		/* If a callback has handled the message, we stop now */
-		if (!*pmsg)
+		if (!msgptr)
 			return 0;
 	}
@@ -769,7 +772,7 @@
 	/* Now pass the message to the next step: either forward to another peer, or dispatch to local extensions */
 	if (is_req || qry_src) {
-		CHECK_FCT(fd_fifo_post(fd_g_outgoing, pmsg) );
+		CHECK_FCT(fd_fifo_post(fd_g_outgoing, &msgptr) );
 	} else {
-		CHECK_FCT(fd_fifo_post(fd_g_local, pmsg) );
+		CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) );
 	}
 
@@ -780,5 +783,5 @@
 
 /* The ROUTING-OUT message processing */
-static int msg_rt_out(struct msg ** pmsg)
+static int msg_rt_out(struct msg * msg)
 {
 	struct rt_data * rtd = NULL;
@@ -789,7 +792,8 @@
 	struct avp * avp;
 	struct rtd_candidate * c;
+	struct msg *msgptr = msg;
 	
 	/* Read the message header */
-	CHECK_FCT( fd_msg_hdr(*pmsg, &hdr) );
+	CHECK_FCT( fd_msg_hdr(msgptr, &hdr) );
 	is_req = hdr->msg_flags & CMD_FLAG_REQUEST;
 	
@@ -803,5 +807,5 @@
 
 		/* Retrieve the corresponding query and its origin */
-		CHECK_FCT( fd_msg_answ_getq( *pmsg, &qry ) );
+		CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) );
 		CHECK_FCT( fd_msg_source_get( qry, &qry_src, &qry_src_len ) );
 
@@ -811,7 +815,6 @@
 		CHECK_FCT( fd_peer_getbyid( qry_src, qry_src_len, 0, (void *) &peer ) );
 		if (fd_peer_getstate(peer) != STATE_OPEN) {
-			fd_msg_log( FD_MSG_LOG_DROPPED, *pmsg, "Unable to forward answer to deleted / closed peer '%s'.", qry_src);
-			fd_msg_free(*pmsg);
-			*pmsg = NULL;
+			fd_msg_log( FD_MSG_LOG_DROPPED, msgptr, "Unable to forward answer to deleted / closed peer '%s'.", qry_src);
+			fd_msg_free(msgptr);
 			return 0;
 		}
@@ -822,5 +825,5 @@
 
 		/* Push the message into this peer */
-		CHECK_FCT( fd_out_send(pmsg, NULL, peer, 0) );
+		CHECK_FCT( fd_out_send(&msgptr, NULL, peer, 0) );
 
 		/* We're done with this answer */
@@ -831,5 +834,5 @@
 
 	/* Get the routing data out of the message if any (in case of re-transmit) */
-	CHECK_FCT( fd_msg_rt_get ( *pmsg, &rtd ) );
+	CHECK_FCT( fd_msg_rt_get ( msgptr, &rtd ) );
 
 	/* If there is no routing data already, let's create it */
@@ -851,5 +854,5 @@
 
 		/* Now let's remove all peers from the Route-Records */
-		CHECK_FCT(  fd_msg_browse(*pmsg, MSG_BRW_FIRST_CHILD, &avp, NULL)  );
+		CHECK_FCT(  fd_msg_browse(msgptr, MSG_BRW_FIRST_CHILD, &avp, NULL)  );
 		while (avp) {
 			struct avp_hdr * ahdr;
@@ -862,5 +865,5 @@
 					{
 						if (error_info.pei_errcode) {
-							CHECK_FCT( return_error( pmsg, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
+							CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
 							return 0;
 						} else {
@@ -883,5 +886,5 @@
 	fd_rtd_candidate_extract(rtd, &candidates, FD_SCORE_INI);
 
-	/* Pass the list to registered callbacks (even if it is empty) */
+	/* Pass the list to registered callbacks (even if it is empty list) */
 	{
 		CHECK_FCT( pthread_rwlock_rdlock( &rt_out_lock ) );
@@ -892,10 +895,10 @@
 			struct rt_hdl * rh = (struct rt_hdl *)li;
 
-			TRACE_DEBUG(ANNOYING, "Calling next OUT callback on %p : %p (prio %d)", *pmsg, rh->rt_out_cb, rh->prio);
-			CHECK_FCT_DO( ret = (*rh->rt_out_cb)(rh->cbdata, *pmsg, candidates),
+			TRACE_DEBUG(ANNOYING, "Calling next OUT callback on %p : %p (prio %d)", msgptr, rh->rt_out_cb, rh->prio);
+			CHECK_FCT_DO( ret = (*rh->rt_out_cb)(rh->cbdata, msgptr, candidates),
 				{
-					fd_msg_log( FD_MSG_LOG_DROPPED, *pmsg, "Internal error: an OUT routing callback returned an error (%s)", strerror(ret));
-					fd_msg_free(*pmsg);
-					*pmsg = NULL;
+					fd_msg_log( FD_MSG_LOG_DROPPED, msgptr, "Internal error: an OUT routing callback returned an error (%s)", strerror(ret));
+					fd_msg_free(msgptr);
+					msgptr = NULL;
 					break;
 				} );
@@ -906,5 +909,5 @@
 
 		/* If an error occurred, skip to the next message */
-		if (! *pmsg) {
+		if (! msgptr) {
 			if (rtd)
 				fd_rtd_free(&rtd);
@@ -917,5 +920,5 @@
 
 	/* Save the routing information in the message */
-	CHECK_FCT( fd_msg_rt_associate ( *pmsg, &rtd ) );
+	CHECK_FCT( fd_msg_rt_associate ( msgptr, &rtd ) );
 
 	/* Now try sending the message */
@@ -934,5 +937,5 @@
 		if (fd_peer_getstate(peer) == STATE_OPEN) {
 			/* Send to this one */
-			CHECK_FCT_DO( fd_out_send(pmsg, NULL, peer, 0), continue );
+			CHECK_FCT_DO( fd_out_send(&msgptr, NULL, peer, 0), continue );
 			
 			/* If the sending was successful */
@@ -942,7 +945,7 @@
 
 	/* If the message has not been sent, return an error */
-	if (*pmsg) {
-		fd_msg_log( FD_MSG_LOG_NODELIVER, *pmsg, "No suitable candidate to route the message to." );
-		return_error( pmsg, "DIAMETER_UNABLE_TO_DELIVER", "No suitable candidate to route the message to", NULL);
+	if (msgptr) {
+		fd_msg_log( FD_MSG_LOG_NODELIVER, msgptr, "No suitable candidate to route the message to." );
+		return_error( &msgptr, "DIAMETER_UNABLE_TO_DELIVER", "No suitable candidate to route the message to", NULL);
 	}
 
@@ -977,5 +980,5 @@
 
 /* This is the common thread code (same for routing and dispatching) */
-static void * process_thr(void * arg, int (*action_cb)(struct msg ** pmsg), struct fifo * queue, char * action_name)
+static void * process_thr(void * arg, int (*action_cb)(struct msg * msg), struct fifo * queue, char * action_name)
 {
 	TRACE_ENTRY("%p %p %p %p", arg, action_cb, queue, action_name);
@@ -1040,5 +1043,5 @@
 		
 		/* Now process the message */
-		CHECK_FCT_DO( (*action_cb)(&msg), goto fatal_error);
+		CHECK_FCT_DO( (*action_cb)(msg), goto fatal_error);
 
 		/* We're done with this message */
