realloc in buf_append

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2013-02-18 at 00:06 +0000, David Woodhouse wrote:
> 
> I think I prefer a 'realloc_or_free' function which just *does* what
> what all the existing code already expects: just free the original
> pointer if it fails to allocate the new one.
> 
> void *safe_realloc(void *old, size_t size)
> {
>     void *p = realloc(old, size);
>     if (size && !p)
>         free(old);
>     return p;
> }

And of course we might as well enforce the fact that it assigns the
result back to the original pointer, thus:

/* I always coded as if it worked like this. Now it does. */
#define realloc_inplace(p, size) do {			\
	void *__realloc_old = p;			\
	p = realloc(p, size);				\
	if (size && !p)					\
		free(__realloc_old);			\
    } while (0)

I've pushed this as commit 8dad4f3. Thanks.

-- 
dwmw2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 6171 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/openconnect-devel/attachments/20130218/c4a38b58/attachment.bin>


[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux