drivers/ftdi: free allocated memory

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
This commit is contained in:
Tomas Vanek 2018-02-16 09:13:36 +01:00
parent 71f5f6eb14
commit ff23980434
2 changed files with 19 additions and 1 deletions

View 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;

View 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;