Revert "smalloc: smalloc() already clears memory, scalloc() need not do it again"
authorVincent Fu <vincent.fu@samsung.com>
Thu, 6 Jun 2024 17:57:47 +0000 (13:57 -0400)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 6 Jun 2024 18:03:47 +0000 (14:03 -0400)
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 <vincent.fu@samsung.com>
smalloc.c

index 23243054ec7ab401ee7d89d73db81d3d809dd612..134f3d775e48893ff666d6fefb0a9d238f6db9ad 100644 (file)
--- 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)