From: Zdenek Kabelac <zkabelac@sourceware.org>
To: lvm-devel@redhat.com
Subject: main - device_id: fix memleak and free idname
Date: Fri, 23 Apr 2021 21:05:37 +0000 (GMT) [thread overview]
Message-ID: <20210423210537.E1949394480D@sourceware.org> (raw)
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=80ef9138726c85e837dbb5a7572178f8b972e300
Commit: 80ef9138726c85e837dbb5a7572178f8b972e300
Parent: 65c4f81dc2eebe4096c48159f2fbd1107e284aea
Author: Zdenek Kabelac <zkabelac@redhat.com>
AuthorDate: Fri Apr 23 00:25:14 2021 +0200
Committer: Zdenek Kabelac <zkabelac@redhat.com>
CommitterDate: Fri Apr 23 22:57:08 2021 +0200
device_id: fix memleak and free idname
Remove extra code path used only for 'free()'
and free(idname) on all paths that do not add it to list
and avoid memleak in few cases.
---
lib/device/device_id.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index cf5867dab..1a9705f04 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -1008,21 +1008,24 @@ id_done:
break;
}
}
- if (found_id && !strcmp(id->idname, idname)) {
- free((char *)idname);
- } else if (found_id && strcmp(id->idname, idname)) {
+
+ if (found_id && idname && strcmp(id->idname, idname)) {
dm_list_del(&id->list);
free_did(id);
found_id = 0;
}
if (!found_id) {
- if (!(id = zalloc(sizeof(struct dev_id))))
+ if (!(id = zalloc(sizeof(struct dev_id)))) {
+ free((char *)idname);
return_0;
+ }
id->idtype = idtype;
id->idname = (char *)idname;
id->dev = dev;
dm_list_add(&dev->ids, &id->list);
- }
+ } else
+ free((char*)idname);
+
dev->id = id;
dev->flags |= DEV_MATCHED_USE_ID;
reply other threads:[~2021-04-23 21:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210423210537.E1949394480D@sourceware.org \
--to=zkabelac@sourceware.org \
--cc=lvm-devel@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.