From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from integral2.. (unknown [180.246.147.8]) by gnuweeb.org (Postfix) with ESMTPSA id 61D477E787; Tue, 26 Apr 2022 21:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1651008080; bh=MaGPjasqSG9QqM7/MZaOYOC2oaT0SuNkl59u/q4vUmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WETOftIcNiADW2LcCp0uz2JcEuMxyzwebXv1yR/6mOPoLLjSe5bLzH5PN4+nlN+I1 b0JwJIbDDZ+84itUqyEBVMPK+JMqkZvE0YJS9NBLpmEJX66Cm9reRKscHSg3BHjNgz WzphXCFRhfi3+rJHKLouDjYEmNL5+MyRbzIO8jIDz5b0T401GSNX60p2oHuQ3qn3ZL yNyf7JJjQP/Vjh/D6sqVNCpKUEXuOOGKtKY3eVEMnaYkydlvBkDc9QfP7kxJWgGkQP JaTmgZcCcEfjG7/Sm6gPG/A6xLuQN5LXUKq0VaFOIomMIhwH+NdWN49FaOQbrCJqaH L0YTV9mj1VLhw== From: Ammar Faizi To: Jens Axboe Cc: fio Mailing List , GNU/Weeb Mailing List , Ammar Faizi Subject: [PATCH v1 3/6] stat: Handle `ENOMEM` case on `malloc()` call Date: Wed, 27 Apr 2022 04:20:41 +0700 Message-Id: <20220426212044.78898-4-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220426212044.78898-1-ammarfaizi2@gnuweeb.org> References: <20220426212044.78898-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Ammar Faizi Add error handling on malloc() call to prevent a NULL pointer dereference. Signed-off-by: Ammar Faizi --- stat.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/stat.c b/stat.c index 949af5ed..2d74c3b0 100644 --- a/stat.c +++ b/stat.c @@ -2430,6 +2430,10 @@ void __show_run_stats(void) struct flist_head **opt_lists; runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); + if (!runstats) { + log_err("fio: failed to allocate runstats\n"); + return; + } for (i = 0; i < groupid + 1; i++) init_group_run_stat(&runstats[i]); @@ -2455,7 +2459,16 @@ void __show_run_stats(void) } threadstats = malloc(nr_ts * sizeof(struct thread_stat)); + if (!threadstats) { + log_err("fio: failed to allocate threadstats\n"); + return; + } + opt_lists = malloc(nr_ts * sizeof(struct flist_head *)); + if (!opt_lists) { + log_err("fio: failed to allocate opt_lists\n"); + return; + } for (i = 0; i < nr_ts; i++) { init_thread_stat(&threadstats[i]); -- Ammar Faizi