Repository: redis/redis

Issue:
Potential resource leak? in src/debug.c.
**Describe the bug**

The open() function returns a file descriptor on success or -1 on failure. In the given code snippet, the condition if (!fd) is used to check if open() failed. However, this condition will evaluate to true if the file descriptor is 0, which could be a valid value.

redis/src/debug.c.

To fix this, you should check if open() returned -1 specifically to determine if it failed. The correct condition would be if (fd == -1).

![image](https://github.com/redis/redis/assets/73597061/4d379e0c-db38-451e-ba6e-7474c020cd8b)




Discussion:
this look right, do you want to issue a fix?

Patch:
diff --git a/src/debug.c b/src/debug.c
index facbd6104a8..192b69d9c83 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -2076,7 +2076,7 @@ int memtest_test_linux_anonymous_maps(void) {
     int regions = 0, j;
 
     int fd = openDirectLogFiledes();
-    if (!fd) return 0;
+    if (fd == -1) return 0;
 
     fp = fopen("/proc/self/maps","r");
     if (!fp) {