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 71DF97E7A7; Wed, 27 Apr 2022 09:12:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1651050724; bh=k0PCt1kWnifDSQWCbe1tgCq3N+c43RE7JEOJR6Eg6XA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DucWRR9cLoa8JamLeAxO0cBrvwrUr0opmyxV8OhDm3yyu/2CH+KKHJ6fdKListzuH uj/q9BuAcDqVt4J4SmDHKENd73+HjBV18tgzch7rdnMTrXihPfwqZc1Rc8stNKeln/ TPQ+GcKpPKLeOv15c21TsLi0TFupgXY4T5yIWn0YzRNeBQhqp14NlCJlFBfD2uksct KQXsIaNCHlrfz9UbQfbXqRJ9qxQ/J3CEFD9gbayaxjDrzLWp3LRaIOoiJTonXdOWXP DoFwUSrdo2lSOPg4B0/sBoLqeU0XQIt56QKbUplT8wiumLcGdvEANA3uM0CNLpWjrd SeBdYk18+Z1IA== From: Ammar Faizi To: Jens Axboe Cc: fio Mailing List , GNU/Weeb Mailing List , Ammar Faizi Subject: [PATCH v2 4/6] engines/net: Replace `malloc()` + `memset()` with `calloc()` Date: Wed, 27 Apr 2022 16:11:23 +0700 Message-Id: <20220427091125.114146-5-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220427091125.114146-1-ammarfaizi2@gnuweeb.org> References: <20220427091125.114146-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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