Review at https://gerrit.osmocom.org/2303
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 --- M src/osmo_ss7.c 1 file changed, 4 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/03/2303/1 diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c index 79b0272..cf1948d 100644 --- a/src/osmo_ss7.c +++ b/src/osmo_ss7.c @@ -1242,7 +1242,9 @@ 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 @@ 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); -- To view, visit https://gerrit.osmocom.org/2303 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6798221ccb3c70186c1c51dd34b7823fefd6df58 Gerrit-PatchSet: 1 Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>