]> git.sur5r.net Git - openocd/commitdiff
stlink: avoid null pointer dereference in stlink_usb_close()
authorPaul Fertser <fercerpav@gmail.com>
Sun, 15 Feb 2015 18:37:16 +0000 (21:37 +0300)
committerPaul Fertser <fercerpav@gmail.com>
Mon, 9 Mar 2015 06:38:52 +0000 (06:38 +0000)
Otherwise it happens if stlink can not be opened on start.

Change-Id: I7088f10e61508dae230eccfe576a51498c92f5b8
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2550
Tested-by: jenkins
Reviewed-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-by: Stian Skjelstad <stian@nixia.no>
src/jtag/drivers/stlink_usb.c

index 4959f97cce528c3f905b607e57efc9ad4454ef29..554ffc1edcbfc2e76e6fe9fd558a3dce37f988b1 100644 (file)
@@ -1664,14 +1664,14 @@ static int stlink_speed(void *handle, int khz, bool query)
 }
 
 /** */
-static int stlink_usb_close(void *fd)
+static int stlink_usb_close(void *handle)
 {
-       struct stlink_usb_handle_s *h = fd;
+       struct stlink_usb_handle_s *h = handle;
 
-       if (h->fd)
+       if (h && h->fd)
                jtag_libusb_close(h->fd);
 
-       free(fd);
+       free(h);
 
        return ERROR_OK;
 }