Introduce whine_realloc

Move few patters with whine_malloc, if (successful) copy+free, to a new
whine_realloc. It should do the same thing, but with a help from OS it
can avoid unnecessary copy and free if allocation of more data after
current data is possible.

Added few setting remanining space to 0, because realloc does not use
calloc like whine_malloc does. There is no advantage of zeroing what we
will immediately overwrite. Zero only remaining space.
This commit is contained in:
Petr Menšík
2022-07-18 13:30:07 +02:00
committed by Simon Kelley
parent ba4c7d906b
commit 0666ae3d27
6 changed files with 24 additions and 24 deletions

View File

@@ -336,6 +336,16 @@ void *whine_malloc(size_t size)
return ret;
}
void *whine_realloc(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);
if (!ret)
my_syslog(LOG_ERR, _("failed to reallocate %d bytes"), (int) size);
return ret;
}
int sockaddr_isequal(const union mysockaddr *s1, const union mysockaddr *s2)
{
if (s1->sa.sa_family == s2->sa.sa_family)