[PATCH i-g-t 3/3] lib/igt_kmod: Fix leaking subtest name

Lucas De Marchi lucas.demarchi at intel.com
Tue Nov 5 05:52:55 UTC 2024


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

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 58edac8fa..fb83f17c0 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -1199,7 +1199,7 @@ 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;
+	char *subtest = NULL;
 	DIR *debugfs_dir = NULL;
 	IGT_LIST_HEAD(tests);
 
@@ -1208,7 +1208,7 @@ 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(module_name);
 		if (!igt_debug_on(!subtest)) {
 			char *suffix = strstr(subtest, "_test");
@@ -1216,6 +1216,8 @@ void igt_kunit(const char *module_name, const char *suite, const char *opts)
 			if (suffix)
 				*suffix = '\0';
 		}
+	} else {
+		subtest = strdup(suite);
 	}
 
 	/* We need the base KUnit module loaded if not built-in */
@@ -1262,6 +1264,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