From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 2/5] cdev-alias: fix memory leak in diskuuid handling
Date: Fri, 12 Dec 2025 17:12:50 +0100 [thread overview]
Message-ID: <20251212161424.1627626-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251212161424.1627626-1-a.fatoum@pengutronix.de>
uuid was duplicated but not free'd in error cases. Fix that.
Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- add Sascha's R-b
---
common/cdev-alias.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/common/cdev-alias.c b/common/cdev-alias.c
index 1878553615d2..3732fd90525f 100644
--- a/common/cdev-alias.c
+++ b/common/cdev-alias.c
@@ -43,12 +43,15 @@ static int cdev_alias_resolve_diskuuid(struct cdev_alias_res *cdev_alias_res,
void *data)
{
struct cdev *cdev;
- char *arg;
+ char *str, *arg;
+ int ret = 0;
- arg = xstrdup(uuid);
+ arg = str = xstrdup(uuid);
uuid = strsep(&arg, ".");
- if (!uuid || !*uuid)
- return -EINVAL;
+ if (!uuid || !*uuid) {
+ ret = -EINVAL;
+ goto out;
+ }
for_each_cdev(cdev) {
if (cdev_is_partition(cdev))
@@ -59,14 +62,19 @@ static int cdev_alias_resolve_diskuuid(struct cdev_alias_res *cdev_alias_res,
if (arg) {
cdev = cdev_find_partition(cdev, arg);
- if (!cdev)
- return -ENODEV;
+ if (!cdev) {
+ ret = -ENODEV;
+ break;
+ }
}
- return fn(cdev, data);
+ ret = fn(cdev, data);
+ break;
}
- return 0;
+out:
+ free(str);
+ return ret;
}
static struct cdev_alias_res cdev_alias_aliases[] = {
--
2.47.3
next prev parent reply other threads:[~2025-12-12 16:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-12 16:12 [PATCH v2 1/5] cdev-alias: support referencing diskuuid without child partition Ahmad Fatoum
2025-12-12 16:12 ` Ahmad Fatoum [this message]
2025-12-12 16:12 ` [PATCH v2 3/5] cdev-alias: add support for storage{.removable,.builtin} Ahmad Fatoum
2025-12-12 16:12 ` [PATCH v2 4/5] boot: try builtin and removable media before net for boot.default Ahmad Fatoum
2025-12-12 16:12 ` [PATCH v2 5/5] boot: assign names to bootentry providers Ahmad Fatoum
2025-12-15 8:15 ` [PATCH v2 1/5] cdev-alias: support referencing diskuuid without child partition Sascha Hauer
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=20251212161424.1627626-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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