[PATCH 2/4] [kdrive] Do not check xfree argument for NULL

Peter Hutterer peter.hutterer at who-t.net
Fri Jan 1 16:17:26 PST 2010


On Sat, Jan 02, 2010 at 05:43:26AM +0600, Mikhail Gusarov wrote:
> xfree itself checks for NULL, and even this is not necessary
> as passing NULL to free(3) is safe.
> 
> Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
> ---
>  hw/kdrive/ephyr/ephyr.c          |    6 ++----
>  hw/kdrive/ephyr/ephyrdriext.c    |   21 +++++++++------------
>  hw/kdrive/ephyr/ephyrglxext.c    |   28 ++++++++++++----------------
>  hw/kdrive/ephyr/ephyrhostvideo.c |    6 ++----
>  hw/kdrive/ephyr/ephyrvideo.c     |   19 +++++++------------
>  hw/kdrive/fake/fake.c            |    5 ++---
>  hw/kdrive/linux/bus.c            |    3 +--
>  hw/kdrive/linux/keyboard.c       |    6 ++----
>  hw/kdrive/linux/tslib.c          |    6 ++----
>  hw/kdrive/src/kinfo.c            |   34 +++++++++++-----------------------
>  hw/kdrive/src/kxv.c              |   21 +++++++--------------
>  11 files changed, 57 insertions(+), 98 deletions(-)
> 
> diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
> index 254fcbc..b6a2ada 100644
> --- a/hw/kdrive/ephyr/ephyr.c
> +++ b/hw/kdrive/ephyr/ephyr.c
> @@ -1074,8 +1074,7 @@ MouseInit (KdPointerInfo *pi)
>      ((EphyrPointerPrivate *)pi->driverPrivate)->enabled = FALSE;
>      pi->nAxes = 3;
>      pi->nButtons = 32;
> -    if (pi->name)
> -        xfree(pi->name);
> +    xfree(pi->name);
>      pi->name = strdup("Xephyr virtual mouse");
>      ephyrMouse = pi;
>      return Success;
> @@ -1125,8 +1124,7 @@ EphyrKeyboardInit (KdKeyboardInfo *ki)
>    }
>    ki->minScanCode = ephyrKeySyms.minKeyCode;
>    ki->maxScanCode = ephyrKeySyms.maxKeyCode;
> -  if (ki->name)
> -      xfree(ki->name);
> +  xfree(ki->name);
>    ki->name = strdup("Xephyr virtual keyboard");
>    ephyrKbd = ki;
>    return Success;
> diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
> index f741d74..5f5fd3b 100644
> --- a/hw/kdrive/ephyr/ephyrdriext.c
> +++ b/hw/kdrive/ephyr/ephyrdriext.c
> @@ -440,10 +440,9 @@ ephyrDRIClipNotify (WindowPtr a_win,
>      is_ok = TRUE ;
>  
>  out:
> -    if (rects) {
> -        xfree (rects) ;
> -        rects = NULL ;
> -    }
> +    xfree (rects) ;
> +    rects = NULL ;
> +
>      EPHYR_LOG ("leave. is_ok:%d\n", is_ok) ;
>      /*do cleanup here*/
>  }
> @@ -566,10 +565,9 @@ EphyrDuplicateVisual (unsigned int a_screen,
>  
>      is_ok = TRUE ;
>  out:
> -    if (new_visuals) {
> -        xfree (new_visuals) ;
> -        new_visuals = NULL ;
> -    }
> +    xfree (new_visuals) ;
> +    new_visuals = NULL ;
> +
>      EPHYR_LOG ("leave\n") ; 
>      return is_ok ;
>  }
> @@ -1254,10 +1252,9 @@ ProcXF86DRIGetDrawableInfo (register ClientPtr client)
>                        sizeof(drm_clip_rect_t) * rep.numBackClipRects,
>                        (char *)backClipRects);
>      }
> -    if (clipRects) {
> -        xfree(clipRects);
> -        clipRects = NULL ;
> -    }
> +    xfree(clipRects);
> +    clipRects = NULL ;
> +
>      EPHYR_LOG ("leave\n") ;
>  
>      return (client->noClientException);
> diff --git a/hw/kdrive/ephyr/ephyrglxext.c b/hw/kdrive/ephyr/ephyrglxext.c
> index 63c4ced..a0278cc 100644
> --- a/hw/kdrive/ephyr/ephyrglxext.c
> +++ b/hw/kdrive/ephyr/ephyrglxext.c
> @@ -243,10 +243,9 @@ ephyrGLXGetVisualConfigsReal (__GLXclientState *a_cl,
>  
>  out:
>      EPHYR_LOG ("leave\n") ;
> -    if (props_buf) {
> -        xfree (props_buf) ;
> -        props_buf = NULL ;
> -    }
> +    xfree (props_buf) ;
> +    props_buf = NULL ;
> +
>      return res ;
>  }
>  
> @@ -301,10 +300,9 @@ ephyrGLXGetFBConfigsSGIXReal (__GLXclientState *a_cl,
>  
>  out:
>      EPHYR_LOG ("leave\n") ;
> -    if (props_buf) {
> -        xfree (props_buf) ;
> -        props_buf = NULL ;
> -    }
> +    xfree (props_buf) ;
> +    props_buf = NULL ;
> +
>      return res ;
>  }
>  
> @@ -391,14 +389,12 @@ ephyrGLXQueryServerString(__GLXclientState *a_cl, GLbyte *a_pc)
>  
>  out:
>      EPHYR_LOG ("leave\n") ;
> -    if (server_string) {
> -        xfree (server_string) ;
> -        server_string = NULL;
> -    }
> -    if (buf) {
> -        xfree (buf);
> -        buf = NULL;
> -    }
> +    xfree (server_string) ;
> +    server_string = NULL;
> +
> +    xfree (buf);
> +    buf = NULL;
> +
>      return res ;
>  }
>  
> diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
> index 41c0b75..f4a1b9d 100644
> --- a/hw/kdrive/ephyr/ephyrhostvideo.c
> +++ b/hw/kdrive/ephyr/ephyrhostvideo.c
> @@ -485,10 +485,8 @@ ephyrHostEncodingsDelete (EphyrHostEncoding *a_encodings,
>      if (!a_encodings)
>          return ;
>      for (i=0; i < a_num_encodings; i++) {
> -        if (a_encodings[i].name) {
> -            xfree (a_encodings[i].name) ;
> -            a_encodings[i].name = NULL ;
> -        }
> +        xfree (a_encodings[i].name) ;
> +        a_encodings[i].name = NULL ;
>      }
>      xfree (a_encodings) ;
>  }
> diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
> index 5058ebe..bb2ee10 100644
> --- a/hw/kdrive/ephyr/ephyrvideo.c
> +++ b/hw/kdrive/ephyr/ephyrvideo.c
> @@ -371,10 +371,8 @@ ephyrXVPrivDelete (EphyrXVPriv *a_this)
>          ephyrHostXVAdaptorArrayDelete (a_this->host_adaptors) ;
>          a_this->host_adaptors = NULL ;
>      }
> -    if (a_this->adaptors) {
> -        xfree (a_this->adaptors) ;
> -        a_this->adaptors = NULL ;
> -    }
> +    xfree (a_this->adaptors) ;
> +    a_this->adaptors = NULL ;
>      xfree (a_this) ;
>      EPHYR_LOG ("leave\n") ;
>  }
> @@ -675,14 +673,11 @@ ephyrXVPrivRegisterAdaptors (EphyrXVPriv *a_this,
>      is_ok = TRUE ;
>  
>  out:
> -    if (registered_adaptors) {
> -        xfree (registered_adaptors) ;
> -        registered_adaptors = NULL ;
> -    }
> -    if (adaptors) {
> -        xfree (adaptors) ;
> -        adaptors=NULL ;
> -    }
> +    xfree (registered_adaptors) ;
> +    registered_adaptors = NULL ;
> +    xfree (adaptors) ;
> +    adaptors = NULL ;
> +
>      EPHYR_LOG ("leave\n") ;
>      return is_ok ;
>  }
> diff --git a/hw/kdrive/fake/fake.c b/hw/kdrive/fake/fake.c
> index ff59798..ea88f0e 100644
> --- a/hw/kdrive/fake/fake.c
> +++ b/hw/kdrive/fake/fake.c
> @@ -457,9 +457,8 @@ void
>  fakeCardFini (KdCardInfo *card)
>  {
>      FakePriv	*priv = card->driver;
> -    
> -    if (priv->base)
> -	free (priv->base);
> +
> +    free (priv->base);
>      xfree (priv);
>  }
>  
> diff --git a/hw/kdrive/linux/bus.c b/hw/kdrive/linux/bus.c
> index 93c3ea5..de9b90f 100644
> --- a/hw/kdrive/linux/bus.c
> +++ b/hw/kdrive/linux/bus.c
> @@ -75,8 +75,7 @@ BusInit (KdPointerInfo *pi)
>              if ((fd = open (BusNames[i], 0)) >= 0)
>              {
>                  close(fd);
> -                if (pi->path)
> -                    xfree(pi->path);
> +                xfree(pi->path);
>                  pi->path = strdup(BusNames[i]);
>                  return Success;
>              }
> diff --git a/hw/kdrive/linux/keyboard.c b/hw/kdrive/linux/keyboard.c
> index 53d3c3a..6eed7ae 100644
> --- a/hw/kdrive/linux/keyboard.c
> +++ b/hw/kdrive/linux/keyboard.c
> @@ -737,11 +737,9 @@ LinuxKeyboardInit (KdKeyboardInfo *ki)
>      if (!ki)
>          return !Success;
>  
> -    if (ki->path)
> -        xfree(ki->path);
> +    xfree(ki->path);
>      ki->path = strdup("console");
> -    if (ki->name)
> -        xfree(ki->name);
> +    xfree(ki->name);
>      ki->name = strdup("Linux console keyboard");
>  
>      readKernelMapping (ki);
> diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c
> index a0b989d..322ccc7 100644
> --- a/hw/kdrive/linux/tslib.c
> +++ b/hw/kdrive/linux/tslib.c
> @@ -175,10 +175,8 @@ TslibInit (KdPointerInfo *pi)
>  static void
>  TslibFini (KdPointerInfo *pi)
>  {
> -    if (pi->driverPrivate) {
> -        xfree(pi->driverPrivate);
> -        pi->driverPrivate = NULL;
> -    }
> +    xfree(pi->driverPrivate);
> +    pi->driverPrivate = NULL;
>  }
>  
>  
> diff --git a/hw/kdrive/src/kinfo.c b/hw/kdrive/src/kinfo.c
> index af64156..95afc79 100644
> --- a/hw/kdrive/src/kinfo.c
> +++ b/hw/kdrive/src/kinfo.c
> @@ -138,40 +138,28 @@ KdFreePointer(KdPointerInfo *pi)
>  {
>      InputOption *option, *prev = NULL;
>  
> -    if (pi->name)
> -        xfree(pi->name);
> -    if (pi->path)
> -        xfree(pi->path);
> +    xfree(pi->name);
> +    xfree(pi->path);
>  
>      for (option = pi->options; option; option = option->next) {
> -        if (prev)
> -            xfree(prev);
> -        if (option->key)
> -            xfree(option->key);
> -        if (option->value)
> -            xfree(option->value);
> +        xfree(prev);
> +        xfree(option->key);
> +        xfree(option->value);
>          prev = option;
>      }
>  
> -    if (prev)
> -        xfree(prev);
> -
> +    xfree(prev);
>      xfree(pi);
>  }
>  
>  void
>  KdFreeKeyboard(KdKeyboardInfo *ki)
>  {
> -    if (ki->name)
> -        xfree(ki->name);
> -    if (ki->path)
> -        xfree(ki->path);
> -    if (ki->xkbRules)
> -        xfree(ki->xkbRules);
> -    if (ki->xkbModel)
> -        xfree(ki->xkbModel);
> -    if (ki->xkbLayout)
> -        xfree(ki->xkbLayout);
> +    xfree(ki->name);
> +    xfree(ki->path);
> +    xfree(ki->xkbRules);
> +    xfree(ki->xkbModel);
> +    xfree(ki->xkbLayout);
>      ki->next = NULL;
>      xfree(ki);
>  }
> diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
> index 1ceb8c6..27ecc5d 100644
> --- a/hw/kdrive/src/kxv.c
> +++ b/hw/kdrive/src/kxv.c
> @@ -247,20 +247,18 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
>  {
>     int i;
>  
> -   if(pAdaptor->name)
> -      xfree(pAdaptor->name);
> +   xfree(pAdaptor->name);
>  
>     if(pAdaptor->pEncodings) {
>        XvEncodingPtr pEncode = pAdaptor->pEncodings;
>  
>        for(i = 0; i < pAdaptor->nEncodings; i++, pEncode++) {
> -          if(pEncode->name) xfree(pEncode->name);
> +          xfree(pEncode->name);
>        }
>        xfree(pAdaptor->pEncodings);
>     }
>  
> -   if(pAdaptor->pFormats)
> -      xfree(pAdaptor->pFormats);
> +   xfree(pAdaptor->pFormats);
>  
>     if(pAdaptor->pPorts) {
>        XvPortPtr pPort = pAdaptor->pPorts;
> @@ -283,17 +281,15 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
>        XvAttributePtr pAttribute = pAdaptor->pAttributes;
>  
>        for(i = 0; i < pAdaptor->nAttributes; i++, pAttribute++) {
> -          if(pAttribute->name) xfree(pAttribute->name);
> +          xfree(pAttribute->name);
>        }
>  
>        xfree(pAdaptor->pAttributes);
>     }
>  
> -   if(pAdaptor->nImages)
> -      xfree(pAdaptor->pImages);
> +   xfree(pAdaptor->pImages);
>  
> -   if(pAdaptor->devPriv.ptr)
> -      xfree(pAdaptor->devPriv.ptr);
> +   xfree(pAdaptor->devPriv.ptr);
>  }
>  
>  static Bool
> @@ -1157,12 +1153,9 @@ KdXVCloseScreen(int i, ScreenPtr pScreen)
>         KdXVFreeAdaptor(pa);
>    }
>  
> -  if(pxvs->pAdaptors)
> -    xfree(pxvs->pAdaptors);
> -
> +  xfree(pxvs->pAdaptors);
>    xfree(ScreenPriv);
>  
> -
>    return TRUE;
>  }
>  
> -- 
> 1.6.3.3

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

 
Cheers,
  Peter


More information about the xorg-devel mailing list