implementing qemu_reallocz
PATCH 1/1 implementing qemu_reallocz
Adding a qemu_reallocz implementation.
Signed-off-by Stefano Stabellini <[email protected]>
---
qemu-common.h +1 -0
@@ -96,6 +96,7 @@void *qemu_malloc (size_t size);void *qemu_realloc (void *ptr,size_t size); +void *qemu_reallocz (void *ptr,size_t size);void *qemu_mallocz (size_t size);void qemu_free (void *ptr);char *qemu_strdup (const char *str);
qemu-malloc.c +10 -0
@@ -53,6 +53,16 @@return ptr; } +void *qemu_reallocz (void *ptr,size_t size) +{ +void *res; + res =realloc (ptr, size); +if (!res) +return NULL ; +memset (res,0 , size); +return res; +} +char *qemu_strdup (const char *str) {char *ptr;
qemu-malloc.c line 65
Quoted 13 lines · Stefano Stabellini
Adding a
qemu_realloczimplementation.qemu-malloc.c +10
-0+void *qemu_reallocz (void *ptr,size_t size) +{ +void *res; + res =realloc (ptr, size); +if (!res) +return NULL ; +memset (res,0 , size); +return res; +} +
I think this interface is pretty non-intuitive. My first expectation is that only the grown region would be zero'd, not the whole thing.
In general, if you don't care about the old memory, free()/malloc() would be a better combination. You're just doing extra work by using realloc() here.
Regards,
Anthony Liguori
Quoted 6 lines
char *qemu_strdup(const char *str)
{ char *ptr;