osmo_ss7: Fix memory leak with sock_name on clients at re-connect time

We cannot use osmo_talloc_replace_string() together with
osmo_sock_get_name(), as the latter already creates a dynamically
allocated string, and the former will then make a copy of that
allocation.

Change-Id: I6798221ccb3c70186c1c51dd34b7823fefd6df58
This commit is contained in:
Harald Welte 2017-04-11 19:34:12 +02:00
parent ed18c11de9
commit 8af8d643de
1 changed files with 4 additions and 4 deletions

View File

@ -1242,7 +1242,9 @@ static int xua_cli_connect_cb(struct osmo_stream_cli *cli)
struct osmo_ss7_asp *asp = osmo_stream_cli_get_data(cli);
/* update the socket name */
osmo_talloc_replace_string(asp, &asp->sock_name, osmo_sock_get_name(asp, ofd->fd));
if (asp->sock_name)
talloc_free(asp->sock_name);
asp->sock_name = osmo_sock_get_name(asp, ofd->fd);
LOGPASP(asp, DLSS7, LOGL_INFO, "Client connected %s\n", asp->sock_name);
@ -1537,9 +1539,7 @@ int
osmo_ss7_xua_server_set_local_host(struct osmo_xua_server *xs, const char *local_host)
{
OSMO_ASSERT(ss7_initialized);
if (xs->cfg.local.host)
talloc_free(xs->cfg.local.host);
xs->cfg.local.host = talloc_strdup(xs, local_host);
osmo_talloc_replace_string(xs, &xs->cfg.local.host, local_host);
osmo_stream_srv_link_set_addr(xs->server, xs->cfg.local.host);