From 3eb0f3e964177e20452f98ddff965aac91f0dc82 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 30 Jun 2020 16:21:38 +0100 Subject: [PATCH] sysprof-dump: Move error handling up to avoid a NULL pointer dereference `reader` can be `NULL`, but the `NULL` check was done after potentially dereferencing it. Signed-off-by: Philip Withnall Helps: #40 --- src/tools/sysprof-dump.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/tools/sysprof-dump.c b/src/tools/sysprof-dump.c index 8b996249..24394909 100644 --- a/src/tools/sysprof-dump.c +++ b/src/tools/sysprof-dump.c @@ -56,7 +56,11 @@ main (gint argc, return EXIT_FAILURE; } - reader = sysprof_capture_reader_new (argv[1], &error); + if ((reader = sysprof_capture_reader_new (argv[1], &error)) == NULL) + { + g_printerr ("%s\n", error->message); + return EXIT_FAILURE; + } if (list_files) { @@ -75,12 +79,6 @@ main (gint argc, #define SET_CTR_TYPE(i,t) g_hash_table_insert(ctrtypes, GINT_TO_POINTER(i), GINT_TO_POINTER(t)) #define GET_CTR_TYPE(i) GPOINTER_TO_INT(g_hash_table_lookup(ctrtypes, GINT_TO_POINTER(i))) - if (reader == NULL) - { - g_printerr ("%s\n", error->message); - return EXIT_FAILURE; - } - begin_time = sysprof_capture_reader_get_start_time (reader); end_time = sysprof_capture_reader_get_end_time (reader);