[CI 2/2] lib/igt_kmod: Fix leaking subtest name

Lucas De Marchi lucas.demarchi at intel.com
Thu Nov 21 22:55:10 UTC 2024


Keep it simple, checking by !suite and then assigning subtest
accordingly. Since this is done only once, always call strdup()
and free().

Reviewed-by: Janusz Krzysztofik <janusz.krzysztofik at linux.intel.com>
Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
 lib/igt_kmod.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 5224d36a4..3729a053c 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -1197,8 +1197,8 @@ void igt_kunit(const char *module_name, const char *suite, const char *opts)
 	char debugfs_path[PATH_MAX] = { '\0', };
 	struct igt_ktest tst = { .kmsg = -1, };
 	struct igt_ktap_results *ktap = NULL;
-	const char *subtest = suite;
 	DIR *debugfs_dir = NULL;
+	char *subtest;
 	IGT_LIST_HEAD(tests);
 
 	/*
@@ -1206,7 +1206,9 @@ void igt_kunit(const char *module_name, const char *suite, const char *opts)
 	 * we take the module name, drop the trailing "_test" or "_kunit"
 	 * suffix, if any, and use the result as our IGT subtest name.
 	 */
-	if (!subtest) {
+	if (suite) {
+		subtest = strdup(suite);
+	} else {
 		subtest = strdup(module_name);
 		if (!igt_debug_on(!subtest)) {
 			char *suffix = strstr(subtest, "_test");
@@ -1259,6 +1261,7 @@ void igt_kunit(const char *module_name, const char *suite, const char *opts)
 		igt_ktest_end(&tst);
 	}
 
+	free(subtest);
 	igt_ktest_fini(&tst);
 }
 
-- 
2.47.0



More information about the igt-dev mailing list