From 1f8e0d1a25b31fe3e479de32887f4b52aaf85ca7 Mon Sep 17 00:00:00 2001 From: Vishal Verma Date: Mon, 23 Mar 2020 12:33:21 -0600 Subject: [PATCH] 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. Cc: Dan Williams Reviewed-by: Dan Williams Link: https://lore.kernel.org/r/20200323183321.21889-1-vishal.l.verma@intel.com Signed-off-by: Vishal Verma --- ndctl/namespace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 21252b6a..05505807 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: