]> git.sur5r.net Git - openocd/commitdiff
drivers/ftdi: free allocated memory
authorTomas Vanek <vanekt@fbl.cz>
Fri, 16 Feb 2018 08:13:36 +0000 (09:13 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Thu, 15 Mar 2018 17:10:16 +0000 (17:10 +0000)
Also uses calloc() for mpsse_ctx->write_buffer to prevent a false
positive valgrind report
"Syscall param ioctl(USBDEVFS_SUBMITURB).buffer points to uninitialised bytes(s)"

Change-Id: I91963371d15c21ea0fee4c40c1da86174db44520
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4418
Tested-by: jenkins
src/jtag/drivers/ftdi.c
src/jtag/drivers/mpsse.c

index e69707e5a70ee31236b1b010ef9908b2f5af49f2..7c6709cd5b6273f082baf44b533fb5d3527e4712 100644 (file)
@@ -694,6 +694,18 @@ static int ftdi_quit(void)
 {
        mpsse_close(mpsse_ctx);
 
+       struct signal *sig = signals;
+       while (sig) {
+               struct signal *next = sig->next;
+               free((void *)sig->name);
+               free(sig);
+               sig = next;
+       }
+
+       free(ftdi_device_desc);
+       free(ftdi_serial);
+       free(ftdi_location);
+
        free(swd_cmd_queue);
 
        return ERROR_OK;
index 924c974502af9ac8b3f5acfdfcd37077642f7a2d..06d008b476b18403a56e1f5ca43f0b213c5ea281 100644 (file)
@@ -335,7 +335,13 @@ struct mpsse_ctx *mpsse_open(const uint16_t *vid, const uint16_t *pid, const cha
        ctx->write_size = 16384;
        ctx->read_chunk = malloc(ctx->read_chunk_size);
        ctx->read_buffer = malloc(ctx->read_size);
-       ctx->write_buffer = malloc(ctx->write_size);
+
+       /* Use calloc to make valgrind happy: buffer_write() sets payload
+        * on bit basis, so some bits can be left uninitialized in write_buffer.
+        * Although this is perfectly ok with MPSSE, valgrind reports
+        * Syscall param ioctl(USBDEVFS_SUBMITURB).buffer points to uninitialised byte(s) */
+       ctx->write_buffer = calloc(1, ctx->write_size);
+
        if (!ctx->read_chunk || !ctx->read_buffer || !ctx->write_buffer)
                goto error;