[PATCH] input: add valuator_mask_free() to free a valuator mask.

Fernando Carrijo fcarrijo at freedesktop.org
Wed Jan 5 19:45:43 PST 2011


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

> Expecting the caller to free the mask requires us to keep it in a single
> memory block (which may be an issue lateron), aside from leaving the API
> asymetrical. Provide valuator_mask_free() to free the memory and reset the
> mask pointer to NULL.
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

Reviewed-by: Fernando Carrijo <fcarrijo at freedesktop.org>

> ---
> bit of an oversight in the first patchset...
> 
>  dix/inpututils.c |    8 ++++++++
>  include/input.h  |    1 +
>  test/input.c     |    3 ++-
>  3 files changed, 11 insertions(+), 1 deletions(-)
> 
> diff --git a/dix/inpututils.c b/dix/inpututils.c
> index 2877804..ef3142c 100644
> --- a/dix/inpututils.c
> +++ b/dix/inpututils.c
> @@ -433,6 +433,14 @@ valuator_mask_new(int num_valuators)
>      return mask;
>  }
>  
> +void
> +valuator_mask_free(ValuatorMask **mask)
> +{
> +    free(*mask);
> +    *mask = NULL;
> +}
> +
> +
>  /**
>   * Sets a range of valuators between first_valuator and num_valuators with
>   * the data in the valuators array. All other values are set to 0.
> diff --git a/include/input.h b/include/input.h
> index 9f3227f..412150c 100644
> --- a/include/input.h
> +++ b/include/input.h
> @@ -567,6 +567,7 @@ extern _X_HIDDEN void valuator_set_mode(DeviceIntPtr dev, int axis, int mode);
>  extern Bool EnableCursor;
>  
>  extern _X_EXPORT ValuatorMask  *valuator_mask_new(int num_valuators);
> +extern _X_EXPORT void valuator_mask_free(ValuatorMask **mask);
>  extern _X_EXPORT void valuator_mask_set_range(ValuatorMask *mask,
>                                         int first_valuator, int num_valuators,
>                                         const int* valuators);
> diff --git a/test/input.c b/test/input.c
> index 1fe228c..39d0bad 100644
> --- a/test/input.c
> +++ b/test/input.c
> @@ -1017,7 +1017,8 @@ static void dix_input_valuator_masks(void)
>          g_assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
>      }
>  
> -    free(mask);
> +    valuator_mask_free(&mask);
> +    g_assert(mask == NULL);
>  }
>  
>  static void dix_valuator_mode(void)
> -- 
> 1.7.3.4
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel


More information about the xorg-devel mailing list