aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-11-25 15:35:50 +0100
committerHarald Welte <laforge@osmocom.org>2021-11-25 15:52:26 +0100
commit9e34f08d0b649f9a40b79eb036bd23ecc5bd80d4 (patch)
tree4859e2de3c3faa60317b513e7785c1a9b670254e
parente352715eb1b589da9de25064de9e890075c56d0b (diff)
gsmtap: Add gsmtap_sendmsg_free() as alternative to gsmtap_sendmsg()
gsmtap_sendmsg() places the burden of freeing the msgb in case of erroneous return codes on the caller. A review of existing users shows that this is overly optimistic and many calls get it wrong, opening up memory leaks. Let's add a new function gsmtap_sendmsg_free() which behaves like gsmtap_sendmsg() but always takes ownership: Either it is sent + freed, or it is just freed. Change-Id: I106b09f2a49bf24ce0e8d11fd4d4ee93e9cafdf5 Related: OS#5329
-rw-r--r--include/osmocom/core/gsmtap_util.h1
-rw-r--r--src/gsmtap_util.c14
2 files changed, 15 insertions, 0 deletions
diff --git a/include/osmocom/core/gsmtap_util.h b/include/osmocom/core/gsmtap_util.h
index e5643260..1cc8d75d 100644
--- a/include/osmocom/core/gsmtap_util.h
+++ b/include/osmocom/core/gsmtap_util.h
@@ -48,6 +48,7 @@ struct gsmtap_inst *gsmtap_source_init(const char *host, uint16_t port,
int gsmtap_source_add_sink(struct gsmtap_inst *gti);
int gsmtap_sendmsg(struct gsmtap_inst *gti, struct msgb *msg);
+int gsmtap_sendmsg_free(struct gsmtap_inst *gti, struct msgb *msg);
int gsmtap_send_ex(struct gsmtap_inst *gti, uint8_t type, uint16_t arfcn, uint8_t ts,
uint8_t chan_type, uint8_t ss, uint32_t fn,
diff --git a/src/gsmtap_util.c b/src/gsmtap_util.c
index 9ae06d64..e5adb2f6 100644
--- a/src/gsmtap_util.c
+++ b/src/gsmtap_util.c
@@ -323,6 +323,20 @@ int gsmtap_sendmsg(struct gsmtap_inst *gti, struct msgb *msg)
}
}
+/*! Send a \ref msgb through a GSMTAP source; free the message even if tx queue full.
+ * \param[in] gti GSMTAP instance
+ * \param[in] msg message buffer; always freed, caller must not reference it later.
+ * \return 0 in case of success; negative in case of error
+ */
+int gsmtap_sendmsg_free(struct gsmtap_inst *gti, struct msgb *msg)
+{
+ int rc;
+ rc = gsmtap_sendmsg(gti, msg);
+ if (rc < 0)
+ msgb_free(msg);
+ return rc;
+}
+
/*! send an arbitrary type through GSMTAP.
* See \ref gsmtap_makemsg_ex for arguments
*/