From: Victor Seva <linuxmaniac@torreviejawireless.org>
Date: Sun, 28 Aug 2022 22:59:44 +0200
Subject: [PATCH] pv_headers: use tm.t_find API

---
 src/modules/pv_headers/pv_headers.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/modules/pv_headers/pv_headers.c b/src/modules/pv_headers/pv_headers.c
index 3648335..d713611 100644
--- a/src/modules/pv_headers/pv_headers.c
+++ b/src/modules/pv_headers/pv_headers.c
@@ -571,6 +571,7 @@ int handle_msg_branch_cb(struct sip_msg *msg, unsigned int flags, void *cb)
 
 int handle_msg_reply_cb(struct sip_msg *msg, unsigned int flags, void *cb)
 {
+	int vref = 0;
 	tm_cell_t *t = NULL;
 	sr_xavp_t **backup_xavis = NULL;
 	sr_xavp_t **list = NULL;
@@ -583,18 +584,12 @@ int handle_msg_reply_cb(struct sip_msg *msg, unsigned int flags, void *cb)
 	LM_DBG("msg:%p previous branch:%d\n", msg, _branch);
 	print_cb_flags(flags);
 
-	if(tmb.t_check(msg, &_branch) == -1) {
-		LM_ERR("failed find UAC branch\n");
-	} else {
-		t = tmb.t_gett();
-		if(t == NULL || t == T_UNDEFINED) {
-			LM_DBG("cannot lookup the transaction\n");
-		} else {
-			LM_DBG("T:%p t_check-branch:%d xavi_list:%p branches:%d\n", t,
-					_branch, &t->xavis_list, t->nr_of_outgoings);
-			list = &t->xavis_list;
-			backup_xavis = xavi_set_list(&t->xavis_list);
-		}
+	t = tmb.t_find(msg, &_branch, &vref);
+	if(t != NULL && t != T_UNDEFINED) {
+		LM_DBG("T:%p t_check-branch:%d xavi_list:%p branches:%d\n", t,
+				_branch, &t->xavis_list, t->nr_of_outgoings);
+		list = &t->xavis_list;
+		backup_xavis = xavi_set_list(&t->xavis_list);
 	}
 
 	pvh_get_branch_index(msg, &_branch);
@@ -609,7 +604,7 @@ int handle_msg_reply_cb(struct sip_msg *msg, unsigned int flags, void *cb)
 		xavi_set_list(backup_xavis);
 		LM_DBG("restored backup_xavis:%p\n", *backup_xavis);
 	}
-	if(t) {
+	if(t && vref) {
 		tmb.unref_cell(t);
 		LM_DBG("T:%p unref\n", t);
 	}
