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 DED407E39D; Fri, 29 Apr 2022 00:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1651193247; bh=BIVlGL8l8IAMglU2zlSp1iqYEowik/hP19802rC5wLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ra2z4IeIuhrj2gVuEMgIXJc7wKvqENFjdFE62VCFHhcAj41+iPgd1ZN98Fg5iezfw zVhyXO2Mqic+zqbheSAfqG0RVtC1MP4oT833Q/hUnGpgMRu2x5XUbLHzk5MowVTra0 sjvEzGPAYIl62w9hOXgCUC/fQJoeWP2nZO1DbElfx1tW7K3MZaHsRYTcexdfUiaojG gM5QSKMaeeqagBJ1TwW0xUs91mt+35SxzHKVGyN1hwmq/Zl3QjPMBFJzZgxLdRGiI2 w2qVdyjg9CMdNOe5lkiK5mHjYArGLk1wRQk1ndEcY9w78XfhG9G3Qqa38SDrNnz1YP HQsKrdoiikOSQ== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Alviro Iskandar Setiawan , Niklas Cassel , fio Mailing List , GNU/Weeb Mailing List Subject: [PATCH v1 3/8] engines/net: Add ENOMEM handling on a `malloc()` call Date: Fri, 29 Apr 2022 07:47:00 +0700 Message-Id: <20220429004705.260034-4-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220429004705.260034-1-ammarfaizi2@gnuweeb.org> References: <20220429004705.260034-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Ammar Faizi Replace `malloc()` + `memset()` with `calloc()` to simplify the call. `calloc()` zeroes the allocated memory, so we can avoid `memset()`. Also, handle the `ENOMEM` case. Signed-off-by: Ammar Faizi --- engines/net.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/engines/net.c b/engines/net.c index c6cec584..24c1463d 100644 --- a/engines/net.c +++ b/engines/net.c @@ -1370,9 +1370,9 @@ static int fio_netio_setup(struct thread_data *td) } if (!td->io_ops_data) { - nd = malloc(sizeof(*nd)); - - memset(nd, 0, sizeof(*nd)); + nd = calloc(1, sizeof(*nd)); + if (!nd) + return 1; nd->listenfd = -1; nd->pipes[0] = nd->pipes[1] = -1; td->io_ops_data = nd; @@ -1391,7 +1391,8 @@ static int fio_netio_setup_splice(struct thread_data *td) { struct netio_data *nd; - fio_netio_setup(td); + if (fio_netio_setup(td)) + return 1; nd = td->io_ops_data; if (nd) { -- Ammar Faizi