On Fri, Jun 22, 2012 at 09:57:33AM -0700, Jason Gerecke wrote:
> On Thu, Jun 21, 2012 at 11:31 PM, Peter Hutterer
> <peter.hutte...@who-t.net> wrote:
> > move out: statement up to make sure we free values on error as well.
> >
> > Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
> > ---
> >  tools/xsetwacom.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
> > index 28332d1..923cf64 100644
> > --- a/tools/xsetwacom.c
> > +++ b/tools/xsetwacom.c
> > @@ -1647,10 +1647,10 @@ static void set(Display *dpy, int argc, char **argv)
> >                                PropModeReplace, data, nitems);
> >        XFlush(dpy);
> >
> > +out:
> >        for (i = 0; i < nvals; i++)
> >                free(values[i]);
> >        free(values);
> > -out:
> >        XCloseDevice(dpy, dev);
> >        free(data);
> >  }
> > --
> > 1.7.10.2
> >
> >
> Good catch, but you'll want to keep around a label at the original
> location as well for the 6 goto statements which precede the
> initialization of 'values'. Otherwise even misspelling a parameter
> name will send xsetwacom up in flames :)

and rightly so :P
I just added the initialisation for values and nvals to NULL/0, that does
the job too.

diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
index 28332d1..3a82b16 100644
--- a/tools/xsetwacom.c
+++ b/tools/xsetwacom.c
@@ -1541,8 +1541,8 @@ static void set(Display *dpy, int argc, char **argv)
        long *n;
        char *b;
        int i;
-       char **values;
-       int nvals;
+       char **values = NULL;
+       int nvals = 0;

        if (argc < 2)
        {
@@ -1647,10 +1647,10 @@ static void set(Display *dpy, int argc, char **argv)
                                PropModeReplace, data, nitems);
        XFlush(dpy);

+out:
        for (i = 0; i < nvals; i++)
                free(values[i]);
        free(values);
-out:
        XCloseDevice(dpy, dev);
        free(data);
 }

Cheers,
  Peter

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to