From: Daniel-Constantin Mierla <miconda@gmail.com>
Date: Tue, 30 Aug 2022 10:58:39 +0200
Subject: [PATCH] pv_headers: use t_unset() based on vref instead of resetting
 global t always

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

diff --git a/src/modules/pv_headers/pv_headers.c b/src/modules/pv_headers/pv_headers.c
index d713611..246339f 100644
--- a/src/modules/pv_headers/pv_headers.c
+++ b/src/modules/pv_headers/pv_headers.c
@@ -604,12 +604,12 @@ 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 && vref) {
-		tmb.unref_cell(t);
+	if(t != NULL && t != T_UNDEFINED && vref != 0) {
+		/*  t_find() above has the side effect of setting T and
+			REFerencing T => we must unref and unset it */
+		tmb.t_unset();
 		LM_DBG("T:%p unref\n", t);
 	}
-	tmb.t_sett(T_UNDEFINED, T_BR_UNDEFINED);
-	LM_DBG("reset tm\n");
 
 	return 1;
 }
