mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yunfeng Ye <yeyunfeng@huawei.com>
To: <mhiramat@kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <hushiyuan@huawei.com>, <hewenliang4@huawei.com>
Subject: [PATCH] tools/bootconfig: fix resource leak in apply_xbc()
Date: Thu, 7 May 2020 17:23:36 +0800	[thread overview]
Message-ID: <583a49c9-c27a-931d-e6c2-6f63a4b18bea@huawei.com> (raw)

The @data and @fd is leak in the error path of apply_xbc(), so this
patch fix it.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 tools/bootconfig/main.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 16b9a420e6fd..001076c51712 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -314,6 +314,7 @@ int apply_xbc(const char *path, const char *xbc_path)
 	ret = delete_xbc(path);
 	if (ret < 0) {
 		pr_err("Failed to delete previous boot config: %d\n", ret);
+		free(data);
 		return ret;
 	}

@@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_path)
 	fd = open(path, O_RDWR | O_APPEND);
 	if (fd < 0) {
 		pr_err("Failed to open %s: %d\n", path, fd);
+		free(data);
 		return fd;
 	}
 	/* TODO: Ensure the @path is initramfs/initrd image */
 	ret = write(fd, data, size + 8);
 	if (ret < 0) {
 		pr_err("Failed to apply a boot config: %d\n", ret);
-		return ret;
+		goto out;
 	}
 	/* Write a magic word of the bootconfig */
 	ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
 	if (ret < 0) {
 		pr_err("Failed to apply a boot config magic: %d\n", ret);
-		return ret;
+		goto out;
 	}
+out:
 	close(fd);
 	free(data);

-	return 0;
+	return ret;
 }

 int usage(void)
-- 
1.8.3.1


             reply	other threads:[~2020-05-07  9:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07  9:23 Yunfeng Ye [this message]
2020-05-07 15:56 ` Masami Hiramatsu
2020-05-07 15:58   ` Masami Hiramatsu
2020-05-07 18:16     ` Steven Rostedt
2020-05-07 20:30 Markus Elfring
2020-05-08  6:41 ` Yunfeng Ye

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=583a49c9-c27a-931d-e6c2-6f63a4b18bea@huawei.com \
    --to=yeyunfeng@huawei.com \
    --cc=hewenliang4@huawei.com \
    --cc=hushiyuan@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®