Prevent memory leak in case of failure.
This commit is contained in:
parent
8115ba6c24
commit
25f4402147
@ -57,7 +57,7 @@ int strconv(const char *str, const char *icharset, const char *ocharset,
|
|||||||
|
|
||||||
inbytes = strlen(str);
|
inbytes = strlen(str);
|
||||||
outbytes = (inbytes + 1) * MB_LEN_MAX;
|
outbytes = (inbytes + 1) * MB_LEN_MAX;
|
||||||
out = malloc(outbytes);
|
out = alloca(outbytes);
|
||||||
if (out == NULL) {
|
if (out == NULL) {
|
||||||
return ISO_MEM_ERROR;
|
return ISO_MEM_ERROR;
|
||||||
}
|
}
|
||||||
@ -78,7 +78,11 @@ int strconv(const char *str, const char *icharset, const char *ocharset,
|
|||||||
*ret = '\0';
|
*ret = '\0';
|
||||||
iconv_close(conv);
|
iconv_close(conv);
|
||||||
|
|
||||||
*output = realloc(out, ret - out + 1);
|
*output = malloc(ret - out + 1);
|
||||||
|
if (*output == NULL) {
|
||||||
|
return ISO_MEM_ERROR;
|
||||||
|
}
|
||||||
|
memcpy(*output, out, ret - out + 1);
|
||||||
return ISO_SUCCESS;
|
return ISO_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user