tbf: Add GprsMs* argument to update() and use it in reuse_tbf

Since set_ms() is caled on the new DL TBF, the old DL TBF loses the
reference to the MS object. This will lead to a segfault, when
update() is called in reuse_tbf().

This commit adds an optional GprsMs* parameter to update() and uses it
for the slot allocation.

This fixes a TbfTest crash that would otherwise occur after applying
the next commit.

Sponsored-by: On-Waves ehf
diff --git a/src/tbf.cpp b/src/tbf.cpp
index ddc3b91..e83873a 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -263,18 +263,24 @@
 	talloc_free(tbf);
 }
 
-int gprs_rlcmac_tbf::update()
+int gprs_rlcmac_tbf::update(GprsMs *ms_)
 {
 	struct gprs_rlcmac_bts *bts_data = bts->bts_data();
-	int rc;
+	int rc = -EINVAL;
 
 	LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF update **********\n");
 
 	if (direction != GPRS_RLCMAC_DL_TBF)
 		return -EINVAL;
 
+	if (!ms_)
+		ms_ = ms();
+
+	if (!ms_)
+		return -EINVAL;
+
 	tbf_unlink_pdch(this);
-	rc = bts_data->alloc_algorithm(bts_data, ms(), this, bts_data->alloc_algorithm_curst, 0);
+	rc = bts_data->alloc_algorithm(bts_data, ms_, this, bts_data->alloc_algorithm_curst, 0);
 	/* if no resource */
 	if (rc < 0) {
 		LOGP(DRLCMAC, LOGL_ERROR, "No resource after update???\n");
diff --git a/src/tbf.h b/src/tbf.h
index 840125a..82ade4e 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -131,7 +131,7 @@
 
 	int rlcmac_diag();
 
-	int update();
+	int update(GprsMs *ms = NULL);
 	void handle_timeout();
 	void stop_timer();
 	void stop_t3191();
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index c7a04bf..771b35b 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -869,7 +869,7 @@
 	state_flags &= GPRS_RLCMAC_FLAG_TO_MASK;
 	state_flags &= ~(1 << GPRS_RLCMAC_FLAG_CCCH);
 
-	update();
+	update(new_tbf->ms());
 
 	LOGP(DRLCMAC, LOGL_DEBUG, "%s Trigger dowlink assignment on PACCH, "
 		"because another LLC PDU has arrived in between\n",