From 8af8d643de2bd6a02c65b2659fd0afa62e865cd6 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 11 Apr 2017 19:34:12 +0200 Subject: [PATCH] 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 --- src/osmo_ss7.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c index 1bcc5c85..24e9fd3c 100644 --- a/src/osmo_ss7.c +++ b/src/osmo_ss7.c @@ -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);