Re: [igt-dev] [PATCH i-g-t] tool/lsgpu: Fix memory leak when no device is found
From: Matt Roper <hidden>
Date: 2021-03-30 18:02:47
On Thu, Mar 18, 2021 at 04:54:26PM -0700, Lucas De Marchi wrote:
From: Ayaz A Siddiqui <redacted> Memory allocated during device scan were not being freed. added call of igt_devices_free(). Cc: Tvrtko Ursulin <redacted> Signed-off-by: Ayaz A Siddiqui <redacted> Signed-off-by: Lucas De Marchi <redacted>
Is this just to appease static analysis? If the program is already terminating, all of the memory is going to immediately get freed by the OS anyway, so I'm not sure it really matters. But the changes here look fine so, Acked-by: Matt Roper <redacted>
quoted hunk ↗ jump to hunk
--- tools/lsgpu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)diff --git a/tools/lsgpu.c b/tools/lsgpu.c index 25358bbe..27e76f26 100644 --- a/tools/lsgpu.c +++ b/tools/lsgpu.c@@ -171,7 +171,7 @@ int main(int argc, char *argv[]) {"help", no_argument, NULL, OPT_HELP}, {0, 0, 0, 0} }; - int c, index = 0; + int c, ret = 0, index = 0; char *env_device = NULL, *opt_device = NULL, *rc_device = NULL; struct igt_devices_print_format fmt = { .type = IGT_PRINT_USER,@@ -257,7 +257,8 @@ int main(int argc, char *argv[]) if (!igt_device_card_match(igt_device, &card)) { printf("No device found for the filter\n\n"); - return -1; + ret = -1; + goto out; } printf("Device detail:\n");@@ -272,9 +273,10 @@ int main(int argc, char *argv[]) } else { igt_devices_print(&fmt); } - +out: + igt_devices_free(); free(rc_device); free(opt_device); - return 0; + return ret; }-- 2.30.1 _______________________________________________ igt-dev mailing list igt-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/igt-dev
-- Matt Roper Graphics Software Engineer VTT-OSGC Platform Enablement Intel Corporation (916) 356-2795 _______________________________________________ igt-dev mailing list igt-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/igt-dev