From b05f7008e49fca23765e1b54c2741af15ad65446 Mon Sep 17 00:00:00 2001 From: Sergey Alirzaev Date: Sun, 20 Mar 2016 05:28:07 +0300 Subject: [PATCH] avoid reading from NULL --- src/stlink-usb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/stlink-usb.c b/src/stlink-usb.c index 8e52c68..b0ee00b 100644 --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@ -720,8 +720,8 @@ stlink_t* stlink_open_usb(const int verbose, int reset, char *p_usb_iserial) { sl = malloc(sizeof (stlink_t)); slu = malloc(sizeof (struct stlink_libusb)); - if (sl == NULL) goto on_error; - if (slu == NULL) goto on_error; + if (sl == NULL) goto on_malloc_error; + if (slu == NULL) goto on_malloc_error; memset(sl, 0, sizeof (stlink_t)); memset(slu, 0, sizeof (struct stlink_libusb)); @@ -867,6 +867,7 @@ on_libusb_error: on_error: if( slu->libusb_ctx) libusb_exit(slu->libusb_ctx); +on_malloc_error: if (sl != NULL) free(sl); if (slu != NULL) free(slu); return NULL; -- 2.39.5