This is an automated email from Gerrit.

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

-- gerrit

commit 8bf451729bb7795db8d0751ca87891f8c372a1ac
Author: Samuel Obuch <[email protected]>
Date:   Fri Sep 25 13:31:53 2020 +0200

    jtag/core.c: Fix memory leak when openocd failed before init
    
    There are two pointers to dynamicly alocated driver data, adapter_driver
    and jtag. Before init, there is only adapter_driver and during init
    it's value is assigned to jtag. However, only jtag is ever freed.
    
    Therefore, there is a memory leak if init is never called.
    This commit fixes this issue by freeing adapter_driver instead of jtag.
    
    Change-Id: I4c57d752f4e6901d919f0bb6c8b948cbadb7042c
    Signed-off-by: Samuel Obuch <[email protected]>

diff --git a/src/jtag/core.c b/src/jtag/core.c
index 03a26be..f511223 100644
--- a/src/jtag/core.c
+++ b/src/jtag/core.c
@@ -1651,13 +1651,16 @@ int jtag_init_inner(struct command_context *cmd_ctx)
 
 int adapter_quit(void)
 {
-       if (jtag && jtag->quit) {
+       if (adapter_driver && adapter_driver->quit) {
                /* close the JTAG interface */
-               int result = jtag->quit();
+               int result = adapter_driver->quit();
                if (ERROR_OK != result)
                        LOG_ERROR("failed: %d", result);
        }
 
+       adapter_driver = NULL;
+       jtag = NULL;
+
        struct jtag_tap *t = jtag_all_taps();
        while (t) {
                struct jtag_tap *n = t->next_tap;
diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c
index 4fa83ae..8f8fc53 100644
--- a/src/jtag/drivers/ftdi.c
+++ b/src/jtag/drivers/ftdi.c
@@ -703,6 +703,10 @@ static int ftdi_quit(void)
 
        free(swd_cmd_queue);
 
+       ftdi_device_desc = NULL;
+       ftdi_serial = NULL;
+       swd_cmd_queue = NULL;
+
        return ERROR_OK;
 }
 
diff --git a/src/jtag/drivers/mpsse.c b/src/jtag/drivers/mpsse.c
index fe8b6b8..6064ec7 100644
--- a/src/jtag/drivers/mpsse.c
+++ b/src/jtag/drivers/mpsse.c
@@ -399,6 +399,9 @@ error:
 
 void mpsse_close(struct mpsse_ctx *ctx)
 {
+       if (!ctx)
+               return;
+
        if (ctx->usb_dev)
                libusb_close(ctx->usb_dev);
        if (ctx->usb_ctx)

-- 


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

Reply via email to