[PATCH]libX11: rm redundant null checks
walter harms
wharms at bfs.de
Fri Jun 6 13:53:05 PDT 2014
this patch removes a bunch of redundant null checks for Xfree()
Signed-off-by: Harms <wharms at bfs,de>
---
modules/im/ximcp/imCallbk.c | 6 +--
modules/im/ximcp/imDefIc.c | 7 ++-
modules/im/ximcp/imDefIm.c | 6 +--
modules/im/ximcp/imDefLkup.c | 13 +++---
modules/im/ximcp/imInt.c | 9 ++--
modules/im/ximcp/imLcIm.c | 98 +++++++++++++++++-------------------------
modules/im/ximcp/imRmAttr.c | 24 +++++------
modules/im/ximcp/imThaiIc.c | 18 ++++----
modules/lc/def/lcDefConv.c | 5 +--
modules/lc/gen/lcGenConv.c | 39 ++++++-----------
modules/om/generic/omGeneric.c | 43 +++++++-----------
11 files changed, 105 insertions(+), 163 deletions(-)
diff --git a/modules/im/ximcp/imCallbk.c b/modules/im/ximcp/imCallbk.c
index 07921f8..4e091d8 100644
--- a/modules/im/ximcp/imCallbk.c
+++ b/modules/im/ximcp/imCallbk.c
@@ -553,10 +553,8 @@ static void
_free_memory_for_text(XIMText* text)
{
if (text) {
- if (text->string.multi_byte)
- Xfree(text->string.multi_byte);
- if (text->feedback)
- Xfree(text->feedback);
+ Xfree(text->string.multi_byte);
+ Xfree(text->feedback);
Xfree(text);
}
}
diff --git a/modules/im/ximcp/imDefIc.c b/modules/im/ximcp/imDefIc.c
index 9610a0f..143bd59 100644
--- a/modules/im/ximcp/imDefIc.c
+++ b/modules/im/ximcp/imDefIc.c
@@ -1595,10 +1595,9 @@ _XimProtoCreateIC(
ErrorOnCreatingIC:
_XimUnregisterFilter(ic);
- if (ic->private.proto.ic_resources)
- Xfree(ic->private.proto.ic_resources);
- if (ic->private.proto.ic_inner_resources)
- Xfree(ic->private.proto.ic_inner_resources);
+
+ Xfree(ic->private.proto.ic_resources);
+ Xfree(ic->private.proto.ic_inner_resources);
Xfree(ic);
return (XIC)NULL;
}
diff --git a/modules/im/ximcp/imDefIm.c b/modules/im/ximcp/imDefIm.c
index 9168135..9e877c0 100644
--- a/modules/im/ximcp/imDefIm.c
+++ b/modules/im/ximcp/imDefIm.c
@@ -1775,10 +1775,8 @@ _XimEncodingNegotiation(
detail_ptr, detail_len)))
goto free_preply;
- if (name_ptr)
- Xfree(name_ptr);
- if (detail_ptr)
- Xfree(detail_ptr);
+ Xfree(name_ptr);
+ Xfree(detail_ptr);
if(reply != preply)
Xfree(preply);
diff --git a/modules/im/ximcp/imDefLkup.c b/modules/im/ximcp/imDefLkup.c
index e881234..10dc8f2 100644
--- a/modules/im/ximcp/imDefLkup.c
+++ b/modules/im/ximcp/imDefLkup.c
@@ -599,10 +599,9 @@ _XimUnregCommitInfo(
if (!(info = ic->private.proto.commit_info))
return;
- if (info->string)
- Xfree(info->string);
- if (info->keysym)
- Xfree(info->keysym);
+
+ Xfree(info->string);
+ Xfree(info->keysym);
ic->private.proto.commit_info = info->next;
Xfree(info);
return;
@@ -696,10 +695,8 @@ _XimCommitRecv(
}
if (!(_XimRegCommitInfo(ic, string, string_len, keysym, keysym_len))) {
- if (string)
- Xfree(string);
- if (keysym)
- Xfree(keysym);
+ Xfree(string);
+ Xfree(keysym);
_XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
return False;
}
diff --git a/modules/im/ximcp/imInt.c b/modules/im/ximcp/imInt.c
index ee9f451..bb393e0 100644
--- a/modules/im/ximcp/imInt.c
+++ b/modules/im/ximcp/imInt.c
@@ -239,14 +239,11 @@ Error4 :
Xfree(im);
return NULL;
Error3 :
- if(im->core.im_name)
- Xfree(im->core.im_name);
+ Xfree(im->core.im_name);
Error2:
- if(im->core.res_class)
- Xfree(im->core.res_class);
+ Xfree(im->core.res_class);
Error1:
- if(im->core.res_name)
- Xfree(im->core.res_name);
+ Xfree(im->core.res_name);
Xfree(im);
return NULL;
}
diff --git a/modules/im/ximcp/imLcIm.c b/modules/im/ximcp/imLcIm.c
index 3ab2dfc..96bb61f 100644
--- a/modules/im/ximcp/imLcIm.c
+++ b/modules/im/ximcp/imLcIm.c
@@ -131,13 +131,14 @@ XimFreeDefaultTree(
}
#endif
Xfree (b->tree);
- if (b->mb) Xfree (b->mb);
- if (b->wc) Xfree (b->wc);
- if (b->utf8) Xfree (b->utf8);
b->tree = NULL;
+ Xfree (b->mb);
b->mb = NULL;
+ Xfree (b->wc);
b->wc = NULL;
+ Xfree (b->utf8);
b->utf8 = NULL;
+
b->treeused = b->treesize = 0;
b->mbused = b->mbsize = 0;
b->wcused = b->wcsize = 0;
@@ -151,38 +152,30 @@ _XimLocalIMFree(
XimFreeDefaultTree(&im->private.local.base);
im->private.local.top = 0;
- if(im->core.im_resources) {
- Xfree(im->core.im_resources);
- im->core.im_resources = NULL;
- }
- if(im->core.ic_resources) {
- Xfree(im->core.ic_resources);
- im->core.ic_resources = NULL;
- }
- if(im->core.im_values_list) {
- Xfree(im->core.im_values_list);
- im->core.im_values_list = NULL;
- }
- if(im->core.ic_values_list) {
- Xfree(im->core.ic_values_list);
- im->core.ic_values_list = NULL;
- }
- if(im->core.styles) {
- Xfree(im->core.styles);
- im->core.styles = NULL;
- }
- if(im->core.res_name) {
- Xfree(im->core.res_name);
- im->core.res_name = NULL;
- }
- if(im->core.res_class) {
- Xfree(im->core.res_class);
- im->core.res_class = NULL;
- }
- if(im->core.im_name) {
- Xfree(im->core.im_name);
- im->core.im_name = NULL;
- }
+ Xfree(im->core.im_resources);
+ im->core.im_resources = NULL;
+
+ Xfree(im->core.ic_resources);
+ im->core.ic_resources = NULL;
+
+ Xfree(im->core.im_values_list);
+ im->core.im_values_list = NULL;
+
+ Xfree(im->core.ic_values_list);
+ im->core.ic_values_list = NULL;
+
+ Xfree(im->core.styles);
+ im->core.styles = NULL;
+
+ Xfree(im->core.res_name);
+ im->core.res_name = NULL;
+
+ Xfree(im->core.res_class);
+ im->core.res_class = NULL;
+
+ Xfree(im->core.im_name);
+ im->core.im_name = NULL;
+
if (im->private.local.ctom_conv) {
_XlcCloseConverter(im->private.local.ctom_conv);
im->private.local.ctom_conv = NULL;
@@ -576,19 +569,15 @@ _XimCreateDefaultTree(
encoding, 0, 1, &cachename, &size);
if (cachefd != -1) {
if (_XimLoadCache (cachefd, intname, encoding, size, im)) {
- if (tmpcachedir)
- Xfree (tmpcachedir);
- if (tmpname)
- Xfree (tmpname);
- if (cachename)
- Xfree (cachename);
+ Xfree (tmpcachedir);
+ Xfree (tmpname);
+ Xfree (cachename);
close (cachefd);
return;
}
close (cachefd);
}
- if (cachename)
- Xfree (cachename);
+ Xfree (cachename);
cachename = NULL;
}
@@ -603,12 +592,9 @@ _XimCreateDefaultTree(
euid, 0, &cachename, &size);
if (cachefd != -1) {
if (_XimLoadCache (cachefd, intname, encoding, size, im)) {
- if (tmpcachedir)
- Xfree (tmpcachedir);
- if (tmpname)
- Xfree (tmpname);
- if (cachename)
- Xfree (cachename);
+ Xfree (tmpcachedir);
+ Xfree (tmpname);
+ Xfree (cachename);
close (cachefd);
return;
}
@@ -618,12 +604,9 @@ _XimCreateDefaultTree(
#endif
if (! (fp = _XFopenFile (name, "r"))) {
- if (tmpcachedir)
- Xfree (tmpcachedir);
- if (tmpname)
- Xfree (tmpname);
- if (cachename)
- Xfree (cachename);
+ Xfree (tmpcachedir);
+ Xfree (tmpname);
+ Xfree (cachename);
return;
}
_XimParseStringFile(fp, im);
@@ -636,11 +619,8 @@ _XimCreateDefaultTree(
}
#endif
- if (tmpcachedir)
- Xfree (tmpcachedir);
- if (tmpname)
+ Xfree (tmpcachedir);
Xfree (tmpname);
- if (cachename)
Xfree (cachename);
}
diff --git a/modules/im/ximcp/imRmAttr.c b/modules/im/ximcp/imRmAttr.c
index ad5290e..9d4e462 100644
--- a/modules/im/ximcp/imRmAttr.c
+++ b/modules/im/ximcp/imRmAttr.c
@@ -972,8 +972,7 @@ _XimEncodePreeditValue(
if (!p->value)
return False;
- if (ic->private.proto.preedit_font)
- Xfree(ic->private.proto.preedit_font);
+ Xfree(ic->private.proto.preedit_font);
list_ret = XFontsOfFontSet((XFontSet)p->value,
&struct_list, &name_list);
@@ -1024,8 +1023,7 @@ _XimEncodeStatusValue(
if (!p->value)
return False;
- if (ic->private.proto.status_font)
- Xfree(ic->private.proto.status_font);
+ Xfree(ic->private.proto.status_font);
list_ret = XFontsOfFontSet((XFontSet)p->value,
&struct_list, &name_list);
@@ -1243,8 +1241,7 @@ _XimEncodeSavedStatusValue(
if (!value)
return False;
- if (ic->private.proto.status_font)
- Xfree(ic->private.proto.status_font);
+ Xfree(ic->private.proto.status_font);
list_ret = XFontsOfFontSet((XFontSet)value,
&struct_list, &name_list);
@@ -1460,10 +1457,9 @@ _XimGetAttributeID(
}
_XIMCompileResourceList(res, n);
- if (im->core.im_resources)
- Xfree(im->core.im_resources);
- if (im->core.im_values_list)
- Xfree(im->core.im_values_list);
+ Xfree(im->core.im_resources);
+ Xfree(im->core.im_values_list);
+
im->core.im_resources = res;
im->core.im_num_resources = n;
im->core.im_values_list = values_list;
@@ -1506,10 +1502,10 @@ _XimGetAttributeID(
}
_XIMCompileResourceList(res, n);
- if (im->core.ic_resources)
- Xfree(im->core.ic_resources);
- if (im->core.ic_values_list)
- Xfree(im->core.ic_values_list);
+
+ Xfree(im->core.ic_resources);
+ Xfree(im->core.ic_values_list);
+
im->core.ic_resources = res;
im->core.ic_num_resources = n;
im->core.ic_values_list = values_list;
diff --git a/modules/im/ximcp/imThaiIc.c b/modules/im/ximcp/imThaiIc.c
index 90da143..3137340 100644
--- a/modules/im/ximcp/imThaiIc.c
+++ b/modules/im/ximcp/imThaiIc.c
@@ -65,18 +65,20 @@ _XimThaiDestroyIC(
if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
_XimThaiUnSetFocus(xic);
}
- if(ic->private.local.ic_resources) {
- Xfree(ic->private.local.ic_resources);
- ic->private.local.ic_resources = NULL;
- }
- if (b->tree) Xfree (b->tree);
- if (b->mb) Xfree (b->mb);
- if (b->wc) Xfree (b->wc);
- if (b->utf8) Xfree (b->utf8);
+ Xfree(ic->private.local.ic_resources);
+ ic->private.local.ic_resources = NULL;
+
+ Xfree (b->tree);
b->tree = NULL;
+
+ Xfree (b->mb);
b->mb = NULL;
+
+ Xfree (b->wc);
b->wc = NULL;
+
+ Xfree (b->utf8);
b->utf8 = NULL;
return;
}
diff --git a/modules/lc/def/lcDefConv.c b/modules/lc/def/lcDefConv.c
index 062a782..d83d656 100644
--- a/modules/lc/def/lcDefConv.c
+++ b/modules/lc/def/lcDefConv.c
@@ -579,10 +579,9 @@ static void
close_converter(
XlcConv conv)
{
- if (conv->state)
- Xfree(conv->state);
- Xfree(conv);
+ Xfree(conv->state);
+ Xfree(conv);
}
static XlcConv
diff --git a/modules/lc/gen/lcGenConv.c b/modules/lc/gen/lcGenConv.c
index 76a91bb..145308e 100644
--- a/modules/lc/gen/lcGenConv.c
+++ b/modules/lc/gen/lcGenConv.c
@@ -1225,8 +1225,8 @@ stdc_wcstocts(
goto ret;
ret:
- if (buf)
- Xfree(buf);
+
+ Xfree(buf);
return (unconv_num1 + unconv_num2);
}
@@ -1548,8 +1548,8 @@ stdc_ctstowcs(
goto ret;
ret:
- if (buf)
- Xfree(buf);
+
+ Xfree(buf);
return (unconv_num1 + unconv_num2);
}
@@ -1584,8 +1584,7 @@ stdc_cstowcs(
goto ret;
ret:
- if (buf)
- Xfree(buf);
+ Xfree(buf);
return (unconv_num1 + unconv_num2);
}
@@ -1620,8 +1619,8 @@ mbstocts(
goto ret;
ret:
- if (buf)
- Xfree(buf);
+
+ Xfree(buf);
return (unconv_num1 + unconv_num2);
}
@@ -2071,8 +2070,7 @@ stdc_wcstostr(
goto ret;
ret:
- if (buf)
- Xfree(buf);
+ Xfree(buf);
return (unconv_num1 + unconv_num2);
}
@@ -2346,8 +2344,7 @@ ctstombs(
goto ret;
ret:
- if (buf)
- Xfree(buf);
+ Xfree(buf);
return (unconv_num1 + unconv_num2);
}
@@ -2382,8 +2379,7 @@ cstombs(
goto ret;
ret:
- if (buf)
- Xfree(buf);
+ Xfree(buf);
return (unconv_num1 + unconv_num2);
}
@@ -2591,8 +2587,7 @@ stdc_strtowcs(
goto ret;
ret:
- if (buf)
- Xfree(buf);
+ Xfree(buf);
return (unconv_num1 + unconv_num2);
}
@@ -2605,15 +2600,9 @@ static void
close_converter(
XlcConv conv)
{
- if (conv->state) {
- Xfree(conv->state);
- }
-
- if (conv->methods) {
- Xfree(conv->methods);
- }
-
- Xfree(conv);
+ Xfree(conv->state);
+ Xfree(conv->methods);
+ Xfree(conv);
}
/* -------------------------------------------------------------------------- */
diff --git a/modules/om/generic/omGeneric.c b/modules/om/generic/omGeneric.c
index 0d202c0..a835f00 100644
--- a/modules/om/generic/omGeneric.c
+++ b/modules/om/generic/omGeneric.c
@@ -196,16 +196,12 @@ init_fontset(
return True;
err:
- if(font_set->font_data)
- Xfree(font_set->font_data);
- if(font_set->substitute)
- Xfree(font_set->substitute);
- if(font_set->vmap)
- Xfree(font_set->vmap);
- if(font_set->vrotate)
- Xfree(font_set->vrotate);
- if(font_set)
- Xfree(font_set);
+
+ Xfree(font_set->font_data);
+ Xfree(font_set->substitute);
+ Xfree(font_set->vmap);
+ Xfree(font_set->vrotate);
+ Xfree(font_set);
gen->font_set = (FontSet) NULL;
gen->font_set_num = 0;
return False;
@@ -504,8 +500,8 @@ init_core_part(
return True;
err:
- if (font_name_list)
- Xfree(font_name_list);
+
+ Xfree(font_name_list);
Xfree(font_struct_list);
return False;
@@ -1486,24 +1482,15 @@ destroy_oc(
*/
/* For VW/UDC end */
- if (oc->core.base_name_list)
- Xfree(oc->core.base_name_list);
-
- if (oc->core.font_info.font_name_list)
- XFreeStringList(oc->core.font_info.font_name_list);
-
- if (oc->core.font_info.font_struct_list) {
- Xfree(oc->core.font_info.font_struct_list);
- }
-
- if (oc->core.missing_list.charset_list)
- XFreeStringList(oc->core.missing_list.charset_list);
+ Xfree(oc->core.base_name_list);
+ XFreeStringList(oc->core.font_info.font_name_list);
+ Xfree(oc->core.font_info.font_struct_list);
+ XFreeStringList(oc->core.missing_list.charset_list);
#ifdef notdef
- if (oc->core.res_name)
- Xfree(oc->core.res_name);
- if (oc->core.res_class)
- Xfree(oc->core.res_class);
+
+ Xfree(oc->core.res_name);
+ Xfree(oc->core.res_class);
#endif
Xfree(oc);
--
1.8.4.5
More information about the xorg-devel
mailing list