[PATCH] libosmo-netif[master]: somo_stream_srv_fd_cb(): close socket if NODELAY fails

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun May 14 19:51:53 UTC 2017


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 <laforge at gnumonks.org>



More information about the gerrit-log mailing list