From eb7fe4550ff2a569d0d8c71de16a1ea1e1aaf0a5 Mon Sep 17 00:00:00 2001 From: Vincent Fu Date: Thu, 6 Jun 2024 13:57:47 -0400 Subject: [PATCH] Revert "smalloc: smalloc() already clears memory, scalloc() need not do it again" Originally: smalloc cleared the buffer scalloc did not need to clear the differ Later: 9c3e13e3314da394698ca32f21cc46d46b7cfe47 smalloc was changed to not clear the buffer scalloc was not updated to clear the buffer when the above smalloc change was made Originally smalloc always cleared the buffer. So it wasn't necessary for scalloc to clear it again. But later on smalloc was changed to no longer clear the buffer but scalloc was not changed back to clear the buffer. Reverting this commit makes scalloc clear the buffer again. This reverts commit a640ed36829f3be6d9dd8c7974dba41b9b59e6a5. Fixes: https://github.com/axboe/fio/issues/1772 Signed-off-by: Vincent Fu --- smalloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/smalloc.c b/smalloc.c index 23243054..134f3d77 100644 --- a/smalloc.c +++ b/smalloc.c @@ -566,7 +566,13 @@ void *smalloc(size_t size) void *scalloc(size_t nmemb, size_t size) { - return smalloc(nmemb * size); + void *ret; + + ret = smalloc(nmemb * size); + if (ret) + memset(ret, 0, nmemb * size); + + return ret; } char *smalloc_strdup(const char *str) -- 2.25.1