On 01/05/2011 11:34 PM, Peter Hutterer wrote: > 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 <[email protected]> >>> --- >>> 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.
Ok, so it's just changing the semantics to be cleaner and less error prone. I can live with that :). Reviewed-by: Chase Douglas <[email protected]> _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
