From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: linux-modules@vger.kernel.org
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH] module: fix a memory leak
Date: Wed, 15 Feb 2017 12:18:03 +0100 [thread overview]
Message-ID: <1487157483-12848-1-git-send-email-bgolaszewski@baylibre.com> (raw)
When a module is removed and re-inserted without unrefing, the
kmod_file is unconditionally re-opened. This results in a memory
and file descriptor leak.
Fix it by checking if the file is already open in
kmod_module_insert_module().
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
libkmod/libkmod-module.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index bf6a8d6..57da0a2 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -833,10 +833,12 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod,
return -ENOENT;
}
- mod->file = kmod_file_open(mod->ctx, path);
- if (mod->file == NULL) {
- err = -errno;
- return err;
+ if (!mod->file) {
+ mod->file = kmod_file_open(mod->ctx, path);
+ if (mod->file == NULL) {
+ err = -errno;
+ return err;
+ }
}
if (kmod_file_get_direct(mod->file)) {
--
2.9.3
next reply other threads:[~2017-02-15 11:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-15 11:18 Bartosz Golaszewski [this message]
2017-02-16 16:51 ` [PATCH] module: fix a memory leak Lucas De Marchi
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=1487157483-12848-1-git-send-email-bgolaszewski@baylibre.com \
--to=bgolaszewski@baylibre.com \
--cc=linux-modules@vger.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;
as well as URLs for NNTP newsgroup(s).