From 6d4acefb69b6a6f7fe29bb398ec617d7e3e01a71 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Fri, 17 Nov 2017 15:12:32 +0100 Subject: stream: Avoid re-creating and leaking socket when unneeded In previous implementation, if no reconfiguring is needed, a new socket would be created without closing the old one, leaking the previous socket. Instead, if we don't need reconfiguring, we return 0 as no operation is required. Change-Id: I6c1a7fff63e44840fb5e2bc7ace5e9a61e304987 --- src/stream.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stream.c b/src/stream.c index 71c9b17..d9c3f62 100644 --- a/src/stream.c +++ b/src/stream.c @@ -735,9 +735,13 @@ int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { int ret; - /* we are reconfiguring this socket, close existing first. */ - if ((link->flags & OSMO_STREAM_SRV_F_RECONF) && link->ofd.fd >= 0) + if (link->ofd.fd >= 0) { + /* No reconfigure needed for existing socket, we are fine */ + if (!(link->flags & OSMO_STREAM_SRV_F_RECONF)) + return 0; + /* we are reconfiguring this socket, close existing first. */ osmo_stream_srv_link_close(link); + } link->flags &= ~OSMO_STREAM_SRV_F_RECONF; -- cgit v1.2.3