avoid reading from NULL
authorSergey Alirzaev <zl29ah@gmail.com>
Sun, 20 Mar 2016 02:28:07 +0000 (05:28 +0300)
committerSergey Alirzaev <zl29ah@gmail.com>
Sun, 20 Mar 2016 02:28:07 +0000 (05:28 +0300)
src/stlink-usb.c

index 8e52c6801488459001a69e434a7e1c88831ef486..b0ee00bed4da904fa4111d9947b998ad21c0e88a 100644 (file)
@@ -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;