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

Peter Hutterer peter.hutterer at who-t.net
Wed Jan 5 20:34:48 PST 2011


On Wed, Jan 05, 2011 at 11:00:33PM -0500, Chase Douglas wrote:
> On 01/05/2011 10:12 PM, Peter Hutterer 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>
> > ---
> > 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;
> > +}
> 
> I'm curious why not just a single pointer like traditional free(),
> leaving the task of setting the pointer to NULL to the caller?

there's no usecase I can think of where the original pointer value is
needed after freeing the memory it points to. you'd end up with every caller
just having two LOC instead of one.

there are only a few usecases for not needing to reset the pointer (but
in those case setting it to NULL doesn't hurt anyway). otoh, forgetting to
reset a pointer to NULL after freeing it is quite common and can be painful
to debug.

Cheers,
  Peter


More information about the xorg-devel mailing list