mirror of
http://thekelleys.org.uk/git/dnsmasq.git
synced 2026-10-01 13:12:30 +07:00
Rewrite blockdata_retrieve() and expand_buf() to use realloc().
This commit is contained in:
+6
-8
@@ -193,22 +193,20 @@ void *blockdata_retrieve(struct blockdata *block, size_t len, void *data)
|
||||
{
|
||||
size_t blen;
|
||||
struct blockdata *b;
|
||||
uint8_t *new, *d;
|
||||
uint8_t *d;
|
||||
|
||||
static unsigned int buff_len = 0;
|
||||
static unsigned char *buff = NULL;
|
||||
|
||||
if (!data)
|
||||
{
|
||||
static unsigned int buff_len = 0;
|
||||
static unsigned char *buff = NULL;
|
||||
uint8_t *new;
|
||||
|
||||
if (len > buff_len)
|
||||
{
|
||||
blen = len + 1024;
|
||||
if (!(new = whine_malloc(blen)))
|
||||
if (!(new = whine_realloc(buff, blen)))
|
||||
return NULL;
|
||||
|
||||
if (buff)
|
||||
free(buff);
|
||||
|
||||
buff = new;
|
||||
buff_len = blen;
|
||||
}
|
||||
|
||||
+1
-7
@@ -680,18 +680,12 @@ int expand_buf(struct iovec *iov, size_t size)
|
||||
if (size <= (size_t)iov->iov_len)
|
||||
return 1;
|
||||
|
||||
if (!(new = whine_malloc(size)))
|
||||
if (!(new = whine_realloc(iov->iov_base, size)))
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (iov->iov_base)
|
||||
{
|
||||
memcpy(new, iov->iov_base, iov->iov_len);
|
||||
free(iov->iov_base);
|
||||
}
|
||||
|
||||
iov->iov_base = new;
|
||||
iov->iov_len = size;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user