diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c
index 576c5df..cc91f49 100644
--- a/mesh/mesh-io-generic.c
+++ b/mesh/mesh-io-generic.c
tx = l_queue_remove_if(pvt->tx_pkts, find_by_ad_type,
L_UINT_TO_PTR(data[0]));
l_free(tx);
+
+ if (tx == pvt->tx)
+ pvt->tx = NULL;
+
} while (tx);
- } else {
+ } else {
struct tx_pattern pattern = {
.data = data,
.len = len
tx = l_queue_remove_if(pvt->tx_pkts, find_by_pattern,
&pattern);
l_free(tx);
+
+ if (tx == pvt->tx)
+ pvt->tx = NULL;
+
} while (tx);
}