fix memory leak in modinfo and build warning
This commit is contained in:
parent
0fadfae9bc
commit
3de980656b
57
backport-depmod-do-not-output-.bin-to-stdout.patch
Normal file
57
backport-depmod-do-not-output-.bin-to-stdout.patch
Normal file
@ -0,0 +1,57 @@
|
||||
From 53b30aeba2dedae9f5558f560231d9462e063dfc Mon Sep 17 00:00:00 2001
|
||||
From: Lucas De Marchi <lucas.demarchi@intel.com>
|
||||
Date: Thu, 5 Mar 2020 13:33:10 -0800
|
||||
Subject: [PATCH] depmod: do not output .bin to stdout
|
||||
|
||||
reason:do not output .bin to stdout
|
||||
Conflict:NA
|
||||
Reference:https://lore.kernel.org/linux-modules/20200306075934.3104-1-lucas.demarchi@intel.com/T/#t
|
||||
|
||||
index_write() relies on fseek/ftell to manage the position to which we
|
||||
are write and thus needs the file stream to support it.
|
||||
|
||||
Right now when trying to write the index to stdout we fail with:
|
||||
|
||||
depmod: tools/depmod.c:416: index_write: Assertion `initial_offset >= 0' failed.
|
||||
Aborted (core dumped)
|
||||
|
||||
We have no interest in outputting our index to stdout, so just skip it
|
||||
like is done with other indexes.
|
||||
|
||||
While at it, add/remove some newlines to improve readability.
|
||||
|
||||
Reported-by: Yanko Kaneti <yaneti@declera.com>
|
||||
Fix: b866b2165ae6 ("Lookup aliases in the modules.builtin.modinfo")
|
||||
---
|
||||
tools/depmod.c | 6 +++++-
|
||||
1 file changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/tools/depmod.c b/tools/depmod.c
|
||||
index fbbce10..875e314 100644
|
||||
--- a/tools/depmod.c
|
||||
+++ b/tools/depmod.c
|
||||
@@ -2408,8 +2408,10 @@ static int output_builtin_alias_bin(struct depmod *depmod, FILE *out)
|
||||
struct index_node *idx;
|
||||
struct kmod_list *l, *builtin = NULL;
|
||||
|
||||
- idx = index_create();
|
||||
+ if (out == stdout)
|
||||
+ return 0;
|
||||
|
||||
+ idx = index_create();
|
||||
if (idx == NULL) {
|
||||
ret = -ENOMEM;
|
||||
goto fail;
|
||||
@@ -2456,7 +2458,9 @@ static int output_builtin_alias_bin(struct depmod *depmod, FILE *out)
|
||||
|
||||
if (count)
|
||||
index_write(idx, out);
|
||||
+
|
||||
index_destroy(idx);
|
||||
+
|
||||
fail:
|
||||
if (builtin)
|
||||
kmod_module_unref_list(builtin);
|
||||
--
|
||||
2.23.0
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
From bd96d05256db2ff9a89dbe2e8bb6e26fcb800052 Mon Sep 17 00:00:00 2001
|
||||
From: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
|
||||
Date: Sun, 29 Nov 2020 18:47:36 +0200
|
||||
Subject: [PATCH] depmod: output_builtin_alias_bin: free idx on error path
|
||||
|
||||
reason:depmod: output_builtin_alias_bin free idx on error path
|
||||
Conflict:NA
|
||||
Reference:https://lore.kernel.org/linux-modules/20201129164737.135866-2-yauheni.kaliuta@redhat.com/T/#u
|
||||
|
||||
idx is allocated in the beginning but it's not freed if there is
|
||||
a failure after the allocation.
|
||||
|
||||
Change the error path: return immediately if idx allocation fails
|
||||
and then free it in both success and error path at the end.
|
||||
|
||||
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
|
||||
---
|
||||
tools/depmod.c | 11 ++++-------
|
||||
1 file changed, 4 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/tools/depmod.c b/tools/depmod.c
|
||||
index 875e314..2c03dfe 100644
|
||||
--- a/tools/depmod.c
|
||||
+++ b/tools/depmod.c
|
||||
@@ -2412,10 +2412,8 @@ static int output_builtin_alias_bin(struct depmod *depmod, FILE *out)
|
||||
return 0;
|
||||
|
||||
idx = index_create();
|
||||
- if (idx == NULL) {
|
||||
- ret = -ENOMEM;
|
||||
- goto fail;
|
||||
- }
|
||||
+ if (idx == NULL)
|
||||
+ return -ENOMEM;
|
||||
|
||||
ret = kmod_module_get_builtin(depmod->ctx, &builtin);
|
||||
if (ret < 0) {
|
||||
@@ -2458,13 +2456,12 @@ static int output_builtin_alias_bin(struct depmod *depmod, FILE *out)
|
||||
|
||||
if (count)
|
||||
index_write(idx, out);
|
||||
-
|
||||
- index_destroy(idx);
|
||||
-
|
||||
fail:
|
||||
if (builtin)
|
||||
kmod_module_unref_list(builtin);
|
||||
|
||||
+ index_destroy(idx);
|
||||
+
|
||||
return ret;
|
||||
}
|
||||
|
||||
--
|
||||
2.23.0
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
From 47807c4cfa5ffe1e5da27e3d3056d9b47ba998c5 Mon Sep 17 00:00:00 2001
|
||||
From: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
|
||||
Date: Sun, 29 Nov 2020 18:47:35 +0200
|
||||
Subject: [PATCH] libkmod: kmod_builtin_get_modinfo: free modinfo on error
|
||||
|
||||
reason:kmod_builtin_get_modinfo: free modinfo on error
|
||||
Conflict:NA
|
||||
Reference:https://lore.kernel.org/linux-modules/CAKi4VA+kaWfLZ_Ue-teaJAvDQjfM6G-WK3KmMWVinR-Zg6T64A@mail.gmail.com/T/#t
|
||||
|
||||
The function allocates array but on building it if get_string()
|
||||
fails it returns the error leaving the array allocated. The caller
|
||||
does not care about it in error case either.
|
||||
|
||||
Free it to fix memory leak.
|
||||
|
||||
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
|
||||
---
|
||||
libkmod/libkmod-builtin.c | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/libkmod/libkmod-builtin.c b/libkmod/libkmod-builtin.c
|
||||
index aaec5dd..fc9a376 100644
|
||||
--- a/libkmod/libkmod-builtin.c
|
||||
+++ b/libkmod/libkmod-builtin.c
|
||||
@@ -314,6 +314,7 @@ ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname,
|
||||
offset = get_string(iter, pos, &line, &linesz);
|
||||
if (offset <= 0) {
|
||||
count = (offset) ? -errno : -EOF;
|
||||
+ free(*modinfo);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
--
|
||||
2.23.0
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
From 95ed3e75365b4922f4d5f3e024a26fe230f3a315 Mon Sep 17 00:00:00 2001
|
||||
From: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
|
||||
Date: Sun, 29 Nov 2020 18:47:37 +0200
|
||||
Subject: [PATCH] libkmod: kmod_log_null: qualify ctx argument as const
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
kmod_log_null() does not change ctx (does nothing).
|
||||
|
||||
Fix warnings
|
||||
|
||||
In file included from libkmod/libkmod-index.c:33:
|
||||
libkmod/libkmod-index.c: In function ‘index_mm_open’:
|
||||
libkmod/libkmod-index.c:757:6: warning: passing argument 1 of ‘kmod_log_null’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
|
||||
757 | DBG(ctx, "file=%s\n", filename);
|
||||
|
||||
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
|
||||
---
|
||||
libkmod/libkmod-internal.h | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h
|
||||
index b22ac2a..398af9c 100644
|
||||
--- a/libkmod/libkmod-internal.h
|
||||
+++ b/libkmod/libkmod-internal.h
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "libkmod.h"
|
||||
|
||||
static _always_inline_ _printf_format_(2, 3) void
|
||||
- kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {}
|
||||
+ kmod_log_null(const struct kmod_ctx *ctx, const char *format, ...) {}
|
||||
|
||||
#define kmod_log_cond(ctx, prio, arg...) \
|
||||
do { \
|
||||
--
|
||||
2.23.0
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: kmod
|
||||
Version: 27
|
||||
Release: 3
|
||||
Release: 4
|
||||
Summary: Kernel module management
|
||||
# GPLv2+ is used by programs, LGPLv2+ is used for libraries.
|
||||
License: GPLv2+ and LGPLv2+
|
||||
@ -11,6 +11,10 @@ Source2: depmod.conf.dist
|
||||
|
||||
Patch6000: backport-libkmod-fix-return-error-when-opening-index.patch
|
||||
Patch6001: backport-libkmod-allow-modules.alias.builtin-to-be-optional.patch
|
||||
Patch6002: backport-depmod-do-not-output-.bin-to-stdout.patch
|
||||
Patch6003: backport-libkmod-kmod_builtin_get_modinfo-free-modinfo-on-err.patch
|
||||
Patch6004: backport-depmod-output_builtin_alias_bin-free-idx-on-error-pa.patch
|
||||
Patch6005: backport-libkmod-kmod_log_null-qualify-ctx-argument-as-const.patch
|
||||
Patch9000: bugfix-kmod-20-8-depmod-Don-t-unlinkat-orig-depfile-and-add-fsync.patch
|
||||
|
||||
BuildRequires: gcc chrpath zlib-devel xz-devel libxslt openssl-devel
|
||||
@ -106,6 +110,9 @@ install -m 0644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/depmod.d/dist.conf
|
||||
%doc TODO NEWS README
|
||||
|
||||
%changelog
|
||||
* Thu Jan 14 2021 xinghe <xinghe1@huawei.com> - 27-4
|
||||
- fix memory leak in kmodinfo and build warning
|
||||
|
||||
* Fri Sep 04 2020 xinghe <xinghe1@huawei.com> - 27-3
|
||||
- backport patch to deal with lspci -v error report
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user