[PATCH i-g-t 3/3] lib/igt_kmod: Fix leaking subtest name
Lucas De Marchi
lucas.demarchi at intel.com
Tue Nov 5 14:13:58 UTC 2024
On Tue, Nov 05, 2024 at 11:59:44AM +0100, Janusz Krzysztofik wrote:
>Hi Lucas,
>
>On Tuesday, 5 November 2024 06:52:55 CET Lucas De Marchi wrote:
>> Keep it simple, checking by !suite and then assigning subtest
>> accordingly. Since this is done only once, always call strdup()
>> and free().
>
>Yes, apparently I missed that leak.
>
>>
>> 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);
>
>NIT: For me it would be still more readable if we reverted the condition and
>reordered the bodies of this conditional construct.
agreed
>
>Anyway,
>
>Reviewed-by: Janusz Krzysztofik <janusz.krzysztofik at linux.intel.com>
thanks
Lucas De Marchi
>
>Thanks,
>Janusz
>
>> }
>>
>> /* 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);
>> }
>>
>>
>
>
>
>
More information about the igt-dev
mailing list