diff options
author | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2017-02-15 12:18:03 +0100 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2017-02-16 08:50:01 -0800 |
commit | b1982674ae994b6ceda36dbee3fba3b2a6ba10de (patch) | |
tree | 54c0f30d47094fdc2bcc8fc7d79fa06d70611743 | |
parent | ded0bebca80ac1f20caa488efb412aa72ea8a7fd (diff) | |
download | kmod-b1982674ae994b6ceda36dbee3fba3b2a6ba10de.tar.gz |
module: fix a memory leak
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>
-rw-r--r-- | libkmod/libkmod-module.c | 10 |
1 files 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)) { |