This is an automated email from Gerrit.

Antonio Borneo ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/5701

-- gerrit

commit 21d1c3321368e698f2ed9c370030420dfd8d6b26
Author: Antonio Borneo <[email protected]>
Date:   Mon May 25 21:37:12 2020 +0200

    libusb_helper: fix memory leak when no adapter is found
    
    When jtag_libusb_open() fails to find the adapter, it returns
    error but left libusb initialized causing memory leak of libusb
    internal data.
    Issue found with valgrind when no adapter or board is connected to
    the host, e.g.
        valgrind openocd -f board/st_nucleo_f4.cfg
    
    Close the libusb operations if jtag_libusb_open() has to return
    error.
    
    Change-Id: Ieb2f110be15705dafe80c099e7d83c07056c2a41
    Signed-off-by: Antonio Borneo <[email protected]>

diff --git a/src/jtag/drivers/libusb_helper.c b/src/jtag/drivers/libusb_helper.c
index fbbfb41..184882a 100644
--- a/src/jtag/drivers/libusb_helper.c
+++ b/src/jtag/drivers/libusb_helper.c
@@ -208,6 +208,9 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t 
pids[],
        if (serial_mismatch)
                LOG_INFO("No device matches the serial string");
 
+       if (retval != ERROR_OK)
+               libusb_exit(jtag_libusb_context);
+
        return retval;
 }
 

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to