Index: /pjproject/trunk/pjsip/include/pjsip/sip_dialog.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsip/sip_dialog.h	(revision 375)
+++ /pjproject/trunk/pjsip/include/pjsip/sip_dialog.h	(revision 376)
@@ -409,6 +409,9 @@
  * @param dlg		    The dialog.
  * @param tdata		    The request message to be sent.
- * @param p_tsx		    Optional argument to receive the transaction 
- *			    instance used to send the request.
+ * @param mod_data_id	    Optional module data index to put an optional data
+ *			    into the transaction. If no module data is to be
+ *			    attached, this value should be -1.
+ * @param mod_data	    Optional module data to be attached to the 
+ *			    transaction at mod_data_id index.
  *
  * @return		    PJ_SUCCESS on success.
@@ -416,5 +419,6 @@
 PJ_DECL(pj_status_t) pjsip_dlg_send_request (	pjsip_dialog *dlg,
 						pjsip_tx_data *tdata,
-						pjsip_transaction **p_tsx );
+						int mod_data_id,
+						void *mod_data);
 
 
Index: /pjproject/trunk/pjsip/src/pjsip-simple/evsub.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip-simple/evsub.c	(revision 375)
+++ /pjproject/trunk/pjsip/src/pjsip-simple/evsub.c	(revision 376)
@@ -1149,5 +1149,5 @@
 
     /* Send the request. */
-    status = pjsip_dlg_send_request(sub->dlg, tdata, NULL);
+    status = pjsip_dlg_send_request(sub->dlg, tdata, -1, NULL);
     if (status != PJ_SUCCESS)
 	goto on_return;
@@ -1483,5 +1483,5 @@
 					       tsx->last_tx, &tdata);
 	    if (status == PJ_SUCCESS) 
-		status = pjsip_dlg_send_request(sub->dlg, tdata, NULL);
+		status = pjsip_dlg_send_request(sub->dlg, tdata, -1, NULL);
 	    
 	    if (status != PJ_SUCCESS) {
@@ -1870,5 +1870,5 @@
 						tsx->last_tx, &tdata);
 	    if (status == PJ_SUCCESS)
-		status = pjsip_dlg_send_request( sub->dlg, tdata, NULL );
+		status = pjsip_dlg_send_request( sub->dlg, tdata, -1, NULL );
 
 	    if (status != PJ_SUCCESS) {
Index: /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 375)
+++ /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 376)
@@ -177,5 +177,5 @@
     }
 
-    status = pjsip_dlg_send_request(inv->dlg, tdata, NULL);
+    status = pjsip_dlg_send_request(inv->dlg, tdata, -1, NULL);
     if (status != PJ_SUCCESS) {
 	/* Better luck next time */
@@ -1581,15 +1581,17 @@
 
     if (tdata->msg->type == PJSIP_REQUEST_MSG) {
-	pjsip_transaction *tsx;
 	struct tsx_inv_data *tsx_inv_data;
 
-	status = pjsip_dlg_send_request(inv->dlg, tdata, &tsx);
+	pjsip_dlg_inc_lock(inv->dlg);
+
+	tsx_inv_data = pj_pool_zalloc(inv->pool, sizeof(struct tsx_inv_data));
+	tsx_inv_data->inv = inv;
+
+	pjsip_dlg_dec_lock(inv->dlg);
+
+	status = pjsip_dlg_send_request(inv->dlg, tdata, mod_inv.mod.id, 
+					tsx_inv_data);
 	if (status != PJ_SUCCESS)
 	    return status;
-
-	tsx_inv_data = pj_pool_zalloc(tsx->pool, sizeof(struct tsx_inv_data));
-	tsx_inv_data->inv = inv;
-
-	tsx->mod_data[mod_inv.mod.id] = tsx_inv_data;
 
     } else {
Index: /pjproject/trunk/pjsip/src/pjsip/sip_dialog.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_dialog.c	(revision 375)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_dialog.c	(revision 376)
@@ -932,5 +932,6 @@
 PJ_DEF(pj_status_t) pjsip_dlg_send_request( pjsip_dialog *dlg,
 					    pjsip_tx_data *tdata,
-					    pjsip_transaction **p_tsx )
+					    int mod_data_id,
+					    void *mod_data)
 {
     pjsip_transaction *tsx;
@@ -979,4 +980,8 @@
 	tsx->mod_data[dlg->ua->id] = dlg;
 
+	/* Copy optional caller's mod_data, if present */
+	if (mod_data_id >= 0 && mod_data_id < PJSIP_MAX_MODULE)
+	    tsx->mod_data[mod_data_id] = mod_data;
+
 	/* Increment transaction counter. */
 	++dlg->tsx_count;
@@ -989,7 +994,4 @@
 	}
 
-	if (p_tsx)
-	    *p_tsx = tsx;
-
     } else {
 	status = pjsip_endpt_send_request_stateless(dlg->endpt, tdata, 
@@ -998,6 +1000,4 @@
 	    goto on_error;
 
-	if (p_tsx)
-	    *p_tsx = NULL;
     }
 
@@ -1014,6 +1014,4 @@
     pjsip_tx_data_dec_ref( tdata );
 
-    if (p_tsx)
-	*p_tsx = NULL;
     return status;
 }
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 375)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 376)
@@ -1331,5 +1331,5 @@
 
     /* Send the request. */
-    status = pjsip_dlg_send_request( call->inv->dlg, tdata, NULL);
+    status = pjsip_dlg_send_request( call->inv->dlg, tdata, -1, NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to send MESSAGE request", status);
@@ -1374,5 +1374,5 @@
 
     /* Send the request. */
-    status = pjsip_dlg_send_request( call->inv->dlg, tdata, NULL);
+    status = pjsip_dlg_send_request( call->inv->dlg, tdata, -1, NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to send MESSAGE request", status);
