summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2015-08-09 12:13:30 +0000
committerbapt <bapt@FreeBSD.org>2015-08-09 12:13:30 +0000
commit4e0791ae19940f493464f039e3833c72834cd03a (patch)
treec173a559057cf72179af1a07fc6e732a2929b477 /lib/libc
parent572a3c0af5247a085c9c9873d70db12f7f4f7b57 (diff)
downloadFreeBSD-src-4e0791ae19940f493464f039e3833c72834cd03a.zip
FreeBSD-src-4e0791ae19940f493464f039e3833c72834cd03a.tar.gz
Use more asprintf
Plug memory leak introduced in previous asprintf addition
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/locale/collate.c4
-rw-r--r--lib/libc/locale/setrunelocale.c9
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c
index 681bd79..e87aa1e 100644
--- a/lib/libc/locale/collate.c
+++ b/lib/libc/locale/collate.c
@@ -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);
diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c
index a87e064..67c632e 100644
--- a/lib/libc/locale/setrunelocale.c
+++ b/lib/libc/locale/setrunelocale.c
@@ -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;
OpenPOWER on IntegriCloud