diff --git a/modules/tm/dlg.c b/modules/tm/dlg.c
index 1daab19..10429a9 100644
--- a/modules/tm/dlg.c
+++ b/modules/tm/dlg.c
@@ -126,7 +126,7 @@ int register_dlg_tmcb(int types, dlg_t* dlg, transaction_cb f, void* param)
 		LOG(L_CRIT, "BUG: tm: register_dlg_tmcb: null callback function");
 		return E_BUG;
 	}
-	return insert_tmcb(&dlg->dlg_callbacks, types, f, param);
+	return insert_tmcb(&dlg->dlg_callbacks, types, f, param, NULL);
 }
 
 
diff --git a/modules/tm/h_table.c b/modules/tm/h_table.c
index 6b38496..0880a61 100644
--- a/modules/tm/h_table.c
+++ b/modules/tm/h_table.c
@@ -141,6 +141,8 @@ void free_cell( struct cell* dead_cell )
 	for( cbs=(struct tm_callback*)dead_cell->tmcb_hl.first ; cbs ; ) {
 		cbs_tmp = cbs;
 		cbs = cbs->next;
+		if (cbs_tmp->release)
+			cbs_tmp->release(cbs_tmp->param);
 		shm_free_unsafe( cbs_tmp );
 	}
 
diff --git a/modules/tm/t_hooks.c b/modules/tm/t_hooks.c
index 788172a..57520aa 100644
--- a/modules/tm/t_hooks.c
+++ b/modules/tm/t_hooks.c
@@ -117,7 +117,7 @@ void destroy_tmcb_lists()
 
 /* lockless insert: should be always safe */
 int insert_tmcb(struct tmcb_head_list *cb_list, int types,
-									transaction_cb f, void *param )
+									transaction_cb f, void *param , release_tmcb_param release_func )
 {
 	struct tm_callback *cbp;
 	struct tm_callback *old;
@@ -133,6 +133,7 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
 	/* ... and fill it up */
 	cbp->callback = f;
 	cbp->param = param;
+	cbp->release = release_func;
 	cbp->types = types;
 	cbp->id=0;
 	old=(struct tm_callback*)cb_list->first;
@@ -164,7 +165,7 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
  *                 from mod_init (before forking!).
 */
 int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
-											transaction_cb f, void *param )
+											transaction_cb f, void *param , release_tmcb_param release_func )
 {
 	//struct cell* t;
 	struct tmcb_head_list *cb_list;
@@ -217,7 +218,7 @@ int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
 		cb_list = &(t->tmcb_hl);
 	}
 
-	return insert_tmcb( cb_list, types, f, param );
+	return insert_tmcb( cb_list, types, f, param , release_func );
 }
 
 
diff --git a/modules/tm/t_hooks.h b/modules/tm/t_hooks.h
index 38721fb..8cb623f 100644
--- a/modules/tm/t_hooks.h
+++ b/modules/tm/t_hooks.h
@@ -385,9 +385,11 @@ do{ \
 
 /* callback function prototype */
 typedef void (transaction_cb) (struct cell* t, int type, struct tmcb_params*);
+/*! \brief function to release the callback param */
+typedef void (release_tmcb_param) (void *param);
 /* register callback function prototype */
 typedef int (*register_tmcb_f)(struct sip_msg* p_msg, struct cell *t,
-		int cb_types, transaction_cb f, void *param);
+		int cb_types, transaction_cb f, void *param, release_tmcb_param func);
 
 
 struct tm_callback {
@@ -395,6 +397,7 @@ struct tm_callback {
 	int types;                   /* types of events that trigger the callback*/
 	transaction_cb* callback;    /* callback function */
 	void *param;                 /* param to be passed to callback function */
+	release_tmcb_param *release; /*!< function to release the callback param when the callback is deleted */
 	struct tm_callback* next;
 };
 
@@ -416,6 +419,8 @@ extern struct tmcb_head_list*  local_req_in_tmcb_hl;
 	( local_req_in_tmcb_hl->first!=0 )
 
 
+void empty_tmcb_list(struct tmcb_head_list *head);
+
 int init_tmcb_lists();
 
 void destroy_tmcb_lists();
@@ -423,11 +428,12 @@ void destroy_tmcb_lists();
 
 /* register a callback for several types of events */
 int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
-											transaction_cb f, void *param );
+											transaction_cb f, void *param , release_tmcb_param release_func );
+
 
 /* inserts a callback into the a callback list */
 int insert_tmcb(struct tmcb_head_list *cb_list, int types,
-									transaction_cb f, void *param );
+									transaction_cb f, void *param , release_tmcb_param release_func );
 
 /* run all transaction callbacks for an event type */
 void run_trans_callbacks( int type , struct cell *trans,
diff --git a/modules/tm/uac.c b/modules/tm/uac.c
index 50089c0..4824e8a 100644
--- a/modules/tm/uac.c
+++ b/modules/tm/uac.c
@@ -319,7 +319,7 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
 	/* Register the callbacks after everything is successful and nothing can fail.
 	Otherwise the callback parameter would be freed twise, once from TMCB_DESTROY,
 	and again because of the negative return code. */
-	if(uac_r->cb && insert_tmcb(&(new_cell->tmcb_hl), uac_r->cb_flags, *(uac_r->cb), uac_r->cbp)!=1){
+	if(uac_r->cb && insert_tmcb(&(new_cell->tmcb_hl), uac_r->cb_flags, *(uac_r->cb), uac_r->cbp , NULL )!=1){
 		ret=E_OUT_OF_MEM; 
 		LOG(L_ERR, "t_uac: short of tmcb shmem\n");
 		goto error1;
