Harald Welte has submitted this change and it was merged.

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


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(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index 1bcc5c8..24e9fd3 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: merged
Gerrit-Change-Id: I6798221ccb3c70186c1c51dd34b7823fefd6df58
Gerrit-PatchSet: 3
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder

Reply via email to