From: Paul Fertser Date: Sun, 15 Feb 2015 18:37:16 +0000 (+0300) Subject: stlink: avoid null pointer dereference in stlink_usb_close() X-Git-Tag: v0.9.0-rc1~90 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d019080dfaa6c0c49228ecec2ad0c585ac65cb73;p=openocd stlink: avoid null pointer dereference in stlink_usb_close() Otherwise it happens if stlink can not be opened on start. Change-Id: I7088f10e61508dae230eccfe576a51498c92f5b8 Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/2550 Tested-by: jenkins Reviewed-by: Andreas Färber Reviewed-by: Spencer Oliver Reviewed-by: Stian Skjelstad --- diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 4959f97c..554ffc1e 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -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; }