summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Marangi2023-05-29 15:07:54 +0000
committerChristian Marangi2023-05-29 15:07:54 +0000
commita85a5bc83bde5b485319ca12b6e32c4b7f0b120f (patch)
treeb1ded3b62620fe657a7b38ef478eb195aac2f494
parent462b3a491347e452c15220861949b1d6371fa59e (diff)
downloadustp-master.tar.gz
netif_utils: correctly close fd on read errorHEADmaster
Fix Coverity Scan CID 1521069 reporting leaking fd on read error. Refactor the read error handling and correctly close fd on read error. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
-rw-r--r--netif_utils.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/netif_utils.c b/netif_utils.c
index a842bf7..2bf59c4 100644
--- a/netif_utils.c
+++ b/netif_utils.c
@@ -143,7 +143,10 @@ static int get_port_file(const char *if_name, const char *file)
long res = -1;
TSTM((fd = open(path, O_RDONLY)) >= 0, -1, "%m");
int l;
- TSTM((l = read(fd, buf, sizeof(buf) - 1)) >= 0, -1, "%m");
+ if((l = read(fd, buf, sizeof(buf) - 1)) < 0) {
+ ERROR("Failed to read file %s: error %m", file);
+ return -1;
+ }
if(0 == l)
{
ERROR("Empty %s file", file);