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
This commit is contained in:
Harald Welte 2017-04-08 22:09:57 +02:00
parent a2c2b59165
commit 0bacc71fc2
2 changed files with 8 additions and 14 deletions

View File

@ -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;
}

View File

@ -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;
}