|
From: | Anthony Liguori |
Subject: | Re: [Qemu-devel] [PATCH 2 of 5] [UPDATE] implementing qemu_reallocz |
Date: | Fri, 21 Nov 2008 12:03:57 -0600 |
User-agent: | Thunderbird 2.0.0.17 (X11/20080925) |
Stefano Stabellini wrote:
Adding a qemu_reallocz implementation. +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
char *qemu_strdup(const char *str) { char *ptr;
[Prev in Thread] | Current Thread | [Next in Thread] |