[lvc-project] [PATCH] executor: fix fd leaks in read_btf_vmlinux and find_vf_interface

Pavel Nikulshin p.nikulshin at ispras.ru
Thu Jan 18 18:02:05 MSK 2024


close file descriptors in this functions.
---
 executor/common_linux.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/executor/common_linux.h b/executor/common_linux.h
index 0671ee81f..15c6bc7bf 100644
--- a/executor/common_linux.h
+++ b/executor/common_linux.h
@@ -241,6 +241,7 @@ static void find_vf_interface(void)
 		}
 		address = address->ifa_next;
 	}
+  close(fd);
 	freeifaddrs(addresses);
 	if (!vf_intf.ppid) {
 		memset(&vf_intf, 0, sizeof(struct vf_intf));
@@ -2131,8 +2132,10 @@ static char* read_btf_vmlinux()
 		ssize_t ret = read(fd, buf + bytes_read,
 				   VMLINUX_MAX_SUPPORT_SIZE - bytes_read);
 
-		if (ret < 0 || bytes_read + ret == VMLINUX_MAX_SUPPORT_SIZE)
+		if (ret < 0 || bytes_read + ret == VMLINUX_MAX_SUPPORT_SIZE) {
+			close(fd);
 			return NULL;
+    }
 
 		if (ret == 0)
 			break;
@@ -2140,6 +2143,7 @@ static char* read_btf_vmlinux()
 		bytes_read += ret;
 	}
 
+  close(fd);
 	is_read = true;
 	return buf;
 }
-- 
2.39.2




More information about the lvc-project mailing list