[PATCH] Remove more superfluous if(p!=NULL) checks around free(p); p=NULL; p_foo=0;

Matt Turner mattst88 at gmail.com
Wed Nov 10 07:59:32 PST 2010


On Wed, Nov 10, 2010 at 10:59 AM, Cyril Brulebois <kibi at debian.org> wrote:
> Candidates are detected with this rather fuzzy Coccinelle semantic patch:
>
> @@
> expression E;
> @@
>  if (E != NULL) {
> -   free(E);
>    ...
>  }
> + free(E);
>
> When the remaining bits in “...” are about setting E to NULL and setting
> properties related to E to 0, the conditional gets removed.
>
> Signed-off-by: Cyril Brulebois <kibi at debian.org>
> ---
>  xkb/XKBGAlloc.c |    8 +++-----
>  xkb/XKBMAlloc.c |   16 ++++++----------
>  2 files changed, 9 insertions(+), 15 deletions(-)
>
> diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
> index 3ec9eda..49f370e 100644
> --- a/xkb/XKBGAlloc.c
> +++ b/xkb/XKBGAlloc.c
> @@ -833,11 +833,9 @@ XkbSectionPtr      section;
>     if ((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))
>        return NULL;
>     if ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success)) {
> -       if (section->rows) {
> -           free(section->rows);
> -           section->rows= NULL;
> -           section->sz_rows= section->num_rows= 0;
> -       }
> +       free(section->rows);
> +       section->rows= NULL;
> +       section->sz_rows= section->num_rows= 0;
>        return NULL;
>     }
>     section->name= name;
> diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c
> index 2681ba3..edaa079 100644
> --- a/xkb/XKBMAlloc.c
> +++ b/xkb/XKBMAlloc.c
> @@ -822,11 +822,9 @@ XkbClientMapPtr    map;
>     if (what&XkbKeySymsMask) {
>        free(map->key_sym_map);
>        map->key_sym_map = NULL;
> -       if (map->syms!=NULL) {
> -           free(map->syms);
> -           map->size_syms= map->num_syms= 0;
> -           map->syms= NULL;
> -       }
> +       free(map->syms);
> +       map->syms= NULL;
> +       map->size_syms= map->num_syms= 0;
>     }
>     if ((what&XkbModifierMapMask)&&(map->modmap!=NULL)) {
>        free(map->modmap);
> @@ -856,11 +854,9 @@ XkbServerMapPtr    map;
>     if (what&XkbKeyActionsMask) {
>        free(map->key_acts);
>        map->key_acts = NULL;
> -       if (map->acts!=NULL) {
> -           free(map->acts);
> -           map->num_acts= map->size_acts= 0;
> -           map->acts= NULL;
> -       }
> +       free(map->acts);
> +       map->acts= NULL;
> +       map->num_acts= map->size_acts= 0;
>     }
>     if ((what&XkbKeyBehaviorsMask)&&(map->behaviors!=NULL)) {
>        free(map->behaviors);
> --
> 1.7.2.3

I think this should be OK.

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the xorg-devel mailing list