svn commit: r295176 - head/lib/libc/nls

Bryan Drewery bdrewery at FreeBSD.org
Tue Feb 2 23:34:00 UTC 2016


Author: bdrewery
Date: Tue Feb  2 23:33:58 2016
New Revision: 295176
URL: https://svnweb.freebsd.org/changeset/base/295176

Log:
  Move logic to destroy a struct catentry to its own function.
  
  This will be used later for memory leak handling.
  
  Obtained from:	OneFS
  Sponsored by:	EMC / Isilon Storage Division

Modified:
  head/lib/libc/nls/msgcat.c

Modified: head/lib/libc/nls/msgcat.c
==============================================================================
--- head/lib/libc/nls/msgcat.c	Tue Feb  2 23:23:37 2016	(r295175)
+++ head/lib/libc/nls/msgcat.c	Tue Feb  2 23:33:58 2016	(r295176)
@@ -325,6 +325,21 @@ notfound:
 	return ((char *)s);
 }
 
+static void
+catfree(struct catentry *np)
+{
+
+	if (np->catd != NULL && np->catd != NLERR) {
+		munmap(np->catd->__data, (size_t)np->catd->__size);
+		free(np->catd);
+	}
+	SLIST_REMOVE(&cache, np, catentry, list);
+	free(np->name);
+	free(np->path);
+	free(np->lang);
+	free(np);
+}
+
 int
 catclose(nl_catd catd)
 {
@@ -341,15 +356,8 @@ catclose(nl_catd catd)
 	SLIST_FOREACH(np, &cache, list) {
 		if (catd == np->catd) {
 			np->refcount--;
-			if (np->refcount == 0) {
-				munmap(catd->__data, (size_t)catd->__size);
-				free(catd);
-				SLIST_REMOVE(&cache, np, catentry, list);
-				free(np->name);
-				free(np->path);
-				free(np->lang);
-				free(np);
-			}
+			if (np->refcount == 0)
+				catfree(np);
 			break;
 		}
 	}


More information about the svn-src-all mailing list