diff mbox series

[4/6] emulator: Fix the unchecked return value

Message ID 20201120200712.491219-4-tedd.an@intel.com (mailing list archive)
State Accepted
Delegated to: Luiz Von Dentz
Headers show
Series [1/6] monitor: Fix potential memory leak | expand

Commit Message

Tedd Ho-Jeong An Nov. 20, 2020, 8:07 p.m. UTC
This patch fixes the unchecked return value.
---
 emulator/phy.c    | 10 ++++++++--
 emulator/server.c |  6 +++++-
 2 files changed, 13 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/emulator/phy.c b/emulator/phy.c
index 4517ad107..2ae6ad3a2 100644
--- a/emulator/phy.c
+++ b/emulator/phy.c
@@ -115,7 +115,10 @@  static int create_rx_socket(void)
 	if (fd < 0)
 		return -1;
 
-	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
+		close(fd);
+		return -1;
+	}
 
 	memset(&addr, 0, sizeof(addr));
 	addr.sin_family = AF_INET;
@@ -138,7 +141,10 @@  static int create_tx_socket(void)
 	if (fd < 0)
 		return -1;
 
-	setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt));
+	if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt)) < 0) {
+		close(fd);
+		return -1;
+	}
 
 	return fd;
 }
diff --git a/emulator/server.c b/emulator/server.c
index 3b07a7156..ceb417a40 100644
--- a/emulator/server.c
+++ b/emulator/server.c
@@ -322,7 +322,11 @@  static int open_tcp(void)
 		return -1;
 	}
 
-	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
+		perror("Failed to set socket option");
+		close(fd);
+		return -1;
+	}
 
 	memset(&addr, 0, sizeof(addr));
 	addr.sin_family = AF_INET;