Use more asprintf

Plug memory leak introduced in previous asprintf addition
This commit is contained in:
Baptiste Daroussin 2015-08-09 12:13:30 +00:00
parent b89704cee7
commit 28a20bb3f5
2 changed files with 9 additions and 4 deletions

View File

@ -124,8 +124,10 @@ __collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
if (buf == NULL)
return (_LDP_ERROR);
if ((fd = _open(buf, O_RDONLY)) < 0)
if ((fd = _open(buf, O_RDONLY)) < 0) {
free(buf);
return (_LDP_ERROR);
}
free(buf);
if (_fstat(fd, &sbuf) < 0) {
(void) _close(fd);

View File

@ -97,7 +97,7 @@ __setrunelocale(struct xlocale_ctype *l, const char *encoding)
{
_RuneLocale *rl;
int ret;
char path[PATH_MAX];
char *path;
struct xlocale_ctype saved = *l;
/*
@ -110,13 +110,16 @@ __setrunelocale(struct xlocale_ctype *l, const char *encoding)
}
/* Range checking not needed, encoding length already checked before */
(void) snprintf(path, sizeof (path), "%s/%s/LC_CTYPE",
_PathLocale, encoding);
asprintf(&path, "%s/%s/LC_CTYPE", _PathLocale, encoding);
if (path == NULL)
return (0);
if ((rl = _Read_RuneMagi(path)) == NULL) {
free(path);
errno = EINVAL;
return (errno);
}
free(path);
l->__mbrtowc = NULL;
l->__mbsinit = NULL;