diff options
| author | Christian Marangi | 2023-05-29 15:07:54 +0000 |
|---|---|---|
| committer | Christian Marangi | 2023-05-29 15:07:54 +0000 |
| commit | a85a5bc83bde5b485319ca12b6e32c4b7f0b120f (patch) | |
| tree | b1ded3b62620fe657a7b38ef478eb195aac2f494 | |
| parent | 462b3a491347e452c15220861949b1d6371fa59e (diff) | |
| download | ustp-master.tar.gz | |
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.c | 5 |
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); |