diff mbox series

[ndctl] ndctl/namespace: Fix a resource leak in file_write_infoblock

Message ID 20200323183321.21889-1-vishal.l.verma@intel.com (mailing list archive)
State Accepted
Commit 1f8e0d1a25b31fe3e479de32887f4b52aaf85ca7
Headers show
Series [ndctl] ndctl/namespace: Fix a resource leak in file_write_infoblock | expand

Commit Message

Verma, Vishal L March 23, 2020, 6:33 p.m. UTC
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.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/namespace.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Dan Williams March 23, 2020, 6:40 p.m. UTC | #1
On Mon, Mar 23, 2020 at 11:33 AM Vishal Verma <vishal.l.verma@intel.com> wrote:
>
> 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.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
>  ndctl/namespace.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/ndctl/namespace.c b/ndctl/namespace.c
> index 21252b6..0550580 100644
> --- a/ndctl/namespace.c
> +++ b/ndctl/namespace.c
> @@ -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:

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
diff mbox series

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 21252b6..0550580 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -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: