dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: mwilck@suse.com
To: Christophe Varoqui <christophe.varoqui@opensvc.com>,
	Benjamin Marzinski <bmarzins@redhat.com>
Cc: dm-devel@redhat.com, Martin Wilck <mwilck@suse.com>
Subject: [PATCH] libmultipath: fix memory leak in _check_bindings_file
Date: Wed, 16 Sep 2020 18:26:58 +0200	[thread overview]
Message-ID: <20200916162658.3818-1-mwilck@suse.com> (raw)

From: Martin Wilck <mwilck@suse.com>

We must pass "&line" to the cleanup function, not "line".

Fixes: "libmultipath: add consistency check for alias settings"
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 2 +-
 libmultipath/util.c  | 8 ++++++++
 libmultipath/util.h  | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index de28f25..a7ba485 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -580,7 +580,7 @@ static int _check_bindings_file(const struct config *conf, FILE *file,
 	size_t line_len = 0;
 	ssize_t n;
 
-	pthread_cleanup_push(free, line);
+	pthread_cleanup_push(cleanup_free_ptr, &line);
 	while ((n = getline(&line, &line_len, file)) >= 0) {
 		char *c, *alias, *wwid, *saveptr;
 		const char *mpe_wwid;
diff --git a/libmultipath/util.c b/libmultipath/util.c
index 8412d30..395c710 100644
--- a/libmultipath/util.c
+++ b/libmultipath/util.c
@@ -406,6 +406,14 @@ void cleanup_mutex(void *arg)
 	pthread_mutex_unlock(arg);
 }
 
+void cleanup_free_ptr(void *arg)
+{
+	void **p = arg;
+
+	if (p && *p)
+		free(*p);
+}
+
 struct bitfield *alloc_bitfield(unsigned int maxbit)
 {
 	unsigned int n;
diff --git a/libmultipath/util.h b/libmultipath/util.h
index 94ed872..21a4088 100644
--- a/libmultipath/util.h
+++ b/libmultipath/util.h
@@ -49,6 +49,7 @@ int should_exit(void);
 
 void close_fd(void *arg);
 void cleanup_mutex(void *arg);
+void cleanup_free_ptr(void *arg);
 
 struct scandir_result {
 	struct dirent **di;
-- 
2.28.0

             reply	other threads:[~2020-09-16 16:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16 16:26 mwilck [this message]
2020-09-21 20:25 ` [PATCH] libmultipath: fix memory leak in _check_bindings_file Benjamin Marzinski

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=20200916162658.3818-1-mwilck@suse.com \
    --to=mwilck@suse.com \
    --cc=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).