Review at  https://gerrit.osmocom.org/2610

somo_stream_srv_fd_cb(): close socket if NODELAY fails

We didn't check for cases where setsockopt_nodelay() fails.  Let's check
for that and bail out + close the socket.

Change-Id: I0adbc4cec35be7c36bdf01d4d8fefd6097e9be5d
Fixes: coverity CID#166970
---
M src/stream.c
1 file changed, 14 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/10/2610/1

diff --git a/src/stream.c b/src/stream.c
index add08b8..b96293e 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -431,17 +431,23 @@
                        osmo_stream_cli_reconnect(cli);
                return ret;
        }
-
-       if (cli->flags & OSMO_STREAM_CLI_F_NODELAY)
-               setsockopt_nodelay(cli->ofd.fd, cli->proto, 1);
-
        cli->ofd.fd = ret;
-       if (osmo_fd_register(&cli->ofd) < 0) {
-               close(ret);
-               cli->ofd.fd = -1;
-               return -EIO;
+
+       if (cli->flags & OSMO_STREAM_CLI_F_NODELAY) {
+               ret = setsockopt_nodelay(cli->ofd.fd, cli->proto, 1);
+               if (ret < 0)
+                       goto error_close_socket;
        }
+
+       if (osmo_fd_register(&cli->ofd) < 0)
+               goto error_close_socket;
+
        return 0;
+
+error_close_socket:
+       close(ret);
+       cli->ofd.fd = -1;
+       return -EIO;
 }
 
 /*! \brief Set the NODELAY socket option to avoid Nagle-like behavior

-- 
To view, visit https://gerrit.osmocom.org/2610
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0adbc4cec35be7c36bdf01d4d8fefd6097e9be5d
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <[email protected]>

Reply via email to