tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH 1/3] Remove useless NULL checks before calling free(3) in gettext.c



---
 src/lib/libintl/gettext.c | 53 +++++++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 32 deletions(-)

diff --git a/src/lib/libintl/gettext.c b/src/lib/libintl/gettext.c
index 6591422..ab18caa 100644
--- a/src/lib/libintl/gettext.c
+++ b/src/lib/libintl/gettext.c
@@ -659,12 +659,13 @@ fail:
 static void
 free_sysdep_table(struct mosysdepstr_h **table, uint32_t nstring)
 {
-	uint32_t i;
 
-	for (i=0; i<nstring; i++) {
+	if (! table)
+		return;
+
+	for (uint32_t i = 0; i < nstring; i++) {
 		if (table[i]) {
-			if (table[i]->expanded)
-				free(table[i]->expanded);
+			free(table[i]->expanded);
 			free(table[i]);
 		}
 	}
@@ -680,26 +681,16 @@ unmapit(struct domainbinding *db)
 	if (mohandle->addr && mohandle->addr != MAP_FAILED)
 		munmap(mohandle->addr, mohandle->len);
 	mohandle->addr = NULL;
-	if (mohandle->mo.mo_otable)
-		free(mohandle->mo.mo_otable);
-	if (mohandle->mo.mo_ttable)
-		free(mohandle->mo.mo_ttable);
-	if (mohandle->mo.mo_charset)
-		free(mohandle->mo.mo_charset);
-	if (mohandle->mo.mo_htable)
-		free(mohandle->mo.mo_htable);
-	if (mohandle->mo.mo_sysdep_segs)
-		free(mohandle->mo.mo_sysdep_segs);
-	if (mohandle->mo.mo_sysdep_otable) {
-		free_sysdep_table(mohandle->mo.mo_sysdep_otable,
-				  mohandle->mo.mo_sysdep_nstring);
-	}
-	if (mohandle->mo.mo_sysdep_ttable) {
-		free_sysdep_table(mohandle->mo.mo_sysdep_ttable,
-				  mohandle->mo.mo_sysdep_nstring);
-	}
-	if (mohandle->mo.mo_plural)
-		_gettext_free_plural(mohandle->mo.mo_plural);
+	free(mohandle->mo.mo_otable);
+	free(mohandle->mo.mo_ttable);
+	free(mohandle->mo.mo_charset);
+	free(mohandle->mo.mo_htable);
+	free(mohandle->mo.mo_sysdep_segs);
+	free_sysdep_table(mohandle->mo.mo_sysdep_otable,
+	    mohandle->mo.mo_sysdep_nstring);
+	free_sysdep_table(mohandle->mo.mo_sysdep_ttable,
+	    mohandle->mo.mo_sysdep_nstring);
+	_gettext_free_plural(mohandle->mo.mo_plural);
 	memset(&mohandle->mo, 0, sizeof(mohandle->mo));
 	return 0;
 }
@@ -918,17 +909,15 @@ dcngettext(const char *domainname, const char *msgid1, const char *msgid2,
 	    domainname, db) == NULL)
 		goto fail;
 
-	if (odomainname)
-		free(odomainname);
-	if (ocname)
-		free(ocname);
+	free(odomainname);
+	free(ocname);
+
 	odomainname = strdup(domainname);
 	ocname = strdup(cname);
 	if (!odomainname || !ocname) {
-		if (odomainname)
-			free(odomainname);
-		if (ocname)
-			free(ocname);
+		free(odomainname);
+		free(ocname);
+
 		odomainname = ocname = NULL;
 	}
 	else
-- 
2.1.0



Home | Main Index | Thread Index | Old Index