Skip to contentSkip to conversation

ndctl/namespace: Fix a resource leak in file_write_infoblock

PATCH In review Vishal Verma 2 participants 2 messages Mar 23, 2020 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

PATCH 1/1 ndctl/namespace: Fix a resource leak in file_write_infoblock

Static analysis reported that we were leaking 'fd' in one case in the above function, fix the error handling to go through the 'out' label.

---
 ndctl/namespace.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
ndctl/namespace.c +4 -2
index 21252b6..0550580 100644
@@ -1958,8 +1958,10 @@ static int file_write_infoblock(const char *path)
 	}
 
 	buf = calloc(INFOBLOCK_SZ, 1);
-	if (!buf)
-		return -ENOMEM;
+	if (!buf) {
+		rc = -ENOMEM;
+		goto out;
+	}
 
 	switch (util_nsmode(param.mode)) {
 	case NDCTL_NS_MODE_FSDAX:
Signature · 4 lines
2.21.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Vishal Verma

Static analysis reported that we were leaking 'fd' in one case in the above function, fix the error handling to go through the 'out' label.

---
 ndctl/namespace.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
ndctl/namespace.c +0 -0
index 21252b6..0550580 100644

ndctl/namespace.c static int file_write_infoblock(const char *path) · line 1964

Quoted 9 lines
ndctl/namespace.c +4 -2
@@ -1958,8 +1958,10 @@ static int file_write_infoblock(const char *path)
        }
 
        buf = calloc(INFOBLOCK_SZ, 1);
-       if (!buf)
-               return -ENOMEM;
+       if (!buf) {
+               rc = -ENOMEM;
+               goto out;
+       }

Looks good:

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]