Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Aug 2015 12:13:31 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r286522 - projects/collation/lib/libc/locale
Message-ID:  <201508091213.t79CDVvv007417@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Sun Aug  9 12:13:30 2015
New Revision: 286522
URL: https://svnweb.freebsd.org/changeset/base/286522

Log:
  Use more asprintf
  Plug memory leak introduced in previous asprintf addition

Modified:
  projects/collation/lib/libc/locale/collate.c
  projects/collation/lib/libc/locale/setrunelocale.c

Modified: projects/collation/lib/libc/locale/collate.c
==============================================================================
--- projects/collation/lib/libc/locale/collate.c	Sun Aug  9 11:50:50 2015	(r286521)
+++ projects/collation/lib/libc/locale/collate.c	Sun Aug  9 12:13:30 2015	(r286522)
@@ -124,8 +124,10 @@ __collate_load_tables_l(const char *enco
 	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);

Modified: projects/collation/lib/libc/locale/setrunelocale.c
==============================================================================
--- projects/collation/lib/libc/locale/setrunelocale.c	Sun Aug  9 11:50:50 2015	(r286521)
+++ projects/collation/lib/libc/locale/setrunelocale.c	Sun Aug  9 12:13:30 2015	(r286522)
@@ -97,7 +97,7 @@ __setrunelocale(struct xlocale_ctype *l,
 {
 	_RuneLocale *rl;
 	int ret;
-	char path[PATH_MAX];
+	char *path;
 	struct xlocale_ctype saved = *l;
 
 	/*
@@ -110,13 +110,16 @@ __setrunelocale(struct xlocale_ctype *l,
 	}
 
 	/* 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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508091213.t79CDVvv007417>