[PATCH] libosmo-netif[master]: stream/datagram: Consistently use osmo_talloc_replace_string()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sat Apr 8 20:20:48 UTC 2017


Review at  https://gerrit.osmocom.org/2252

stream/datagram: Consistently use osmo_talloc_replace_string()

during osmo_*_set_addr(), we must make sure to talloc_free() any old
address before copying in the new address.  Not all functions did this,
and those that did implemented it manually.  Let's use
osmo_talloc_replace_string() which is exactly intended for this case.

Change-Id: Ie1b140a160c66e8b62c745174865d5ba525cb2c2
---
M src/datagram.c
M src/stream.c
2 files changed, 8 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/52/2252/1

diff --git a/src/datagram.c b/src/datagram.c
index cb2a64f..13f1b5c 100644
--- a/src/datagram.c
+++ b/src/datagram.c
@@ -39,7 +39,7 @@
 struct osmo_dgram_tx {
 	struct osmo_fd			ofd;
 	struct llist_head		tx_queue;
-	const char			*addr;
+	char				*addr;
 	uint16_t			port;
 	char				*local_addr;
 	uint16_t			local_port;
@@ -125,10 +125,7 @@
 osmo_dgram_tx_set_addr(struct osmo_dgram_tx *conn,
 				const char *addr)
 {
-	if (conn->addr != NULL)
-		talloc_free((void *)conn->addr);
-
-	conn->addr = talloc_strdup(conn, addr);
+	osmo_talloc_replace_string(conn, &conn->addr, addr);
 	conn->flags |= OSMO_DGRAM_CLI_F_RECONF;
 }
 
@@ -224,7 +221,7 @@
 
 struct osmo_dgram_rx {
         struct osmo_fd                  ofd;
-        const char                      *addr;
+        char                            *addr;
         uint16_t                        port;
 	int (*cb)(struct osmo_dgram_rx *conn);
         void                            *data;
@@ -296,10 +293,7 @@
 void osmo_dgram_rx_set_addr(struct osmo_dgram_rx *conn,
 				     const char *addr)
 {
-	if (conn->addr != NULL)
-		talloc_free((void *)conn->addr);
-
-	conn->addr = talloc_strdup(conn, addr);
+	osmo_talloc_replace_string(conn, &conn->addr, addr);
 	conn->flags |= OSMO_DGRAM_RX_F_RECONF;
 }
 
diff --git a/src/stream.c b/src/stream.c
index 52521d7..7bac1cc 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -81,7 +81,7 @@
 	struct llist_head		tx_queue;
 	struct osmo_timer_list		timer;
 	enum osmo_stream_cli_state	state;
-	const char			*addr;
+	char				*addr;
 	uint16_t			port;
 	char				*local_addr;
 	uint16_t			local_port;
@@ -264,7 +264,7 @@
 void
 osmo_stream_cli_set_addr(struct osmo_stream_cli *cli, const char *addr)
 {
-	cli->addr = talloc_strdup(cli, addr);
+	osmo_talloc_replace_string(cli, &cli->addr, addr);
 	cli->flags |= OSMO_STREAM_CLI_F_RECONF;
 }
 
@@ -474,7 +474,7 @@
 
 struct osmo_stream_srv_link {
         struct osmo_fd                  ofd;
-        const char                      *addr;
+        char                            *addr;
         uint16_t                        port;
         uint16_t                        proto;
         int (*accept_cb)(struct osmo_stream_srv_link *srv, int fd);
@@ -537,7 +537,7 @@
 void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link,
 				      const char *addr)
 {
-	link->addr = talloc_strdup(link, addr);
+	osmo_talloc_replace_string(link, &link->addr, addr);
 	link->flags |= OSMO_STREAM_SRV_F_RECONF;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/2252
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1b140a160c66e8b62c745174865d5ba525cb2c2
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list