diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c index 0cba460403b3..3df76b60b4bd 100644 --- a/lib/libc/nls/msgcat.c +++ b/lib/libc/nls/msgcat.c @@ -325,6 +325,21 @@ catgets(nl_catd catd, int set_id, int msg_id, const char *s) 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; } }