mirror of
https://github.com/rfc1036/whois.git
synced 2026-05-03 06:51:09 +00:00
Free memory on error in simple_recode()
Signed-off-by: Petr Písař <ppisar@redhat.com>
This commit is contained in:
parent
298f2080fe
commit
4c8e0be3ce
@ -94,6 +94,7 @@ char *simple_recode(const iconv_t handle, const char *str)
|
||||
{
|
||||
size_t used = outp - result;
|
||||
size_t newsize;
|
||||
char *new_result;
|
||||
|
||||
if (outbuf_size < SIMPLE_RECODE_BUFFER_SIZE_2)
|
||||
newsize = SIMPLE_RECODE_BUFFER_SIZE_2;
|
||||
@ -103,13 +104,17 @@ char *simple_recode(const iconv_t handle, const char *str)
|
||||
|
||||
/* check if the newsize variable has overflowed */
|
||||
if (newsize <= outbuf_size) {
|
||||
free(result);
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
outbuf_size = newsize;
|
||||
result = realloc(result, outbuf_size);
|
||||
if (!result)
|
||||
new_result = realloc(result, outbuf_size);
|
||||
if (!new_result) {
|
||||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
result = new_result;
|
||||
|
||||
/* update the position in the new output stream */
|
||||
outp = result + used;
|
||||
@ -119,6 +124,7 @@ char *simple_recode(const iconv_t handle, const char *str)
|
||||
}
|
||||
|
||||
default:
|
||||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
} while (inbytes_remaining > 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user