aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-04-08 22:09:57 +0200
committerHarald Welte <laforge@gnumonks.org>2017-04-10 06:47:28 +0000
commit0bacc71fc208e5cdf0727de027438b8e901ff666 (patch)
treec67d11c94438a8fcd147392ea4dcb16e96fad458
parenta2c2b59165ebb63ccca0838922501b717d5233a7 (diff)
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
-rw-r--r--src/datagram.c14
-rw-r--r--src/stream.c8
2 files changed, 8 insertions, 14 deletions
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 @@ void
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 @@ void osmo_dgram_tx_send(struct osmo_dgram_tx *conn,
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 @@ struct osmo_dgram_rx *osmo_dgram_rx_create(void *crx)
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 osmo_stream_cli {
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 @@ struct osmo_stream_cli *osmo_stream_cli_create(void *ctx)
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 @@ int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg)
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 @@ struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx)
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;
}