[PATCH v2 1/3] [libx11] Variable "map" goes out of scope

Dirk Wallenstein halsmit at t-online.de
Tue Feb 1 00:08:56 PST 2011


On Mon, Jan 31, 2011 at 12:03:32PM +0200, Erkki Seppälä wrote:
> Release modifiermap before returning. Reordered code to call
> XGetModifierMapping after the first return from the function.
> 
> Signed-off-by: Erkki Seppälä <erkki.seppala at vincit.fi>
> 
> diff --git a/modules/im/ximcp/imThaiFlt.c b/modules/im/ximcp/imThaiFlt.c
> index e0b3988..e2b0458 100644
> --- a/modules/im/ximcp/imThaiFlt.c
> +++ b/modules/im/ximcp/imThaiFlt.c
> @@ -1262,15 +1262,20 @@ Private unsigned
>  NumLockMask(Display *d)
>  {
>      int i;
> -    XModifierKeymap *map = XGetModifierMapping (d);
> +    XModifierKeymap *map;
>      KeyCode numlock_keycode = XKeysymToKeycode (d, XK_Num_Lock);
>      if (numlock_keycode == NoSymbol)
>          return 0;
>  
> +    map = XGetModifierMapping (d);
> +
>      for (i = 0; i < 8; i++) {
> -        if (map->modifiermap[map->max_keypermod * i] == numlock_keycode)
> +        if (map->modifiermap[map->max_keypermod * i] == numlock_keycode) {
> +            XFreeModifiermap(map);
>              return 1 << i;
> +        }
>      }
> +    XFreeModifiermap(map);
>      return 0;
>  }
>  
> -- 
> 1.7.0.4
> 

Reviewed-by: Dirk Wallenstein <halsmit at t-online.de>

A related thing.  XGetModifierMapping can return NULL.  I would suggest
to just return 0 in that case.

-- 
Greetings,
Dirk


More information about the xorg-devel mailing list