jtag: fix clang ulink memory leaks
Memory leaks discovered by clang 3.1 Change-Id: I8a784ba9726deac508424eddb27e9c8409e2773f Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/795 Tested-by: jenkins Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
This commit is contained in:
parent
a25e61ecd3
commit
09f9596ae0
|
@ -532,6 +532,7 @@ int ulink_allocate_payload(struct ulink_cmd *ulink_cmd, int size,
|
||||||
case PAYLOAD_DIRECTION_OUT:
|
case PAYLOAD_DIRECTION_OUT:
|
||||||
if (ulink_cmd->payload_out != NULL) {
|
if (ulink_cmd->payload_out != NULL) {
|
||||||
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
|
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
|
||||||
|
free(payload);
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
} else {
|
} else {
|
||||||
ulink_cmd->payload_out = payload;
|
ulink_cmd->payload_out = payload;
|
||||||
|
@ -541,6 +542,7 @@ int ulink_allocate_payload(struct ulink_cmd *ulink_cmd, int size,
|
||||||
case PAYLOAD_DIRECTION_IN:
|
case PAYLOAD_DIRECTION_IN:
|
||||||
if (ulink_cmd->payload_in_start != NULL) {
|
if (ulink_cmd->payload_in_start != NULL) {
|
||||||
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
|
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
|
||||||
|
free(payload);
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
} else {
|
} else {
|
||||||
ulink_cmd->payload_in_start = payload;
|
ulink_cmd->payload_in_start = payload;
|
||||||
|
@ -896,6 +898,7 @@ int ulink_append_scan_cmd(struct ulink *device, enum scan_type scan_type,
|
||||||
if (scan_size_bits > (58 * 8)) {
|
if (scan_size_bits > (58 * 8)) {
|
||||||
LOG_ERROR("BUG: Tried to create CMD_SCAN_IO OpenULINK command with too"
|
LOG_ERROR("BUG: Tried to create CMD_SCAN_IO OpenULINK command with too"
|
||||||
" large payload");
|
" large payload");
|
||||||
|
free(cmd);
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -934,8 +937,10 @@ int ulink_append_scan_cmd(struct ulink *device, enum scan_type scan_type,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != ERROR_OK)
|
if (ret != ERROR_OK) {
|
||||||
|
free(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* Build payload_out that is common to all scan types */
|
/* Build payload_out that is common to all scan types */
|
||||||
cmd->payload_out[0] = scan_size_bytes & 0xFF;
|
cmd->payload_out[0] = scan_size_bytes & 0xFF;
|
||||||
|
@ -993,8 +998,10 @@ int ulink_append_clock_tms_cmd(struct ulink *device, uint8_t count,
|
||||||
|
|
||||||
/* CMD_CLOCK_TMS has two OUT payload bytes and zero IN payload bytes */
|
/* CMD_CLOCK_TMS has two OUT payload bytes and zero IN payload bytes */
|
||||||
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
|
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
|
||||||
if (ret != ERROR_OK)
|
if (ret != ERROR_OK) {
|
||||||
|
free(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
cmd->payload_out[0] = count;
|
cmd->payload_out[0] = count;
|
||||||
cmd->payload_out[1] = sequence;
|
cmd->payload_out[1] = sequence;
|
||||||
|
@ -1027,8 +1034,10 @@ int ulink_append_clock_tck_cmd(struct ulink *device, uint16_t count)
|
||||||
|
|
||||||
/* CMD_CLOCK_TCK has two OUT payload bytes and zero IN payload bytes */
|
/* CMD_CLOCK_TCK has two OUT payload bytes and zero IN payload bytes */
|
||||||
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
|
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
|
||||||
if (ret != ERROR_OK)
|
if (ret != ERROR_OK) {
|
||||||
|
free(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
cmd->payload_out[0] = count & 0xff;
|
cmd->payload_out[0] = count & 0xff;
|
||||||
cmd->payload_out[1] = (count >> 8) & 0xff;
|
cmd->payload_out[1] = (count >> 8) & 0xff;
|
||||||
|
@ -1057,8 +1066,10 @@ int ulink_append_get_signals_cmd(struct ulink *device)
|
||||||
/* CMD_GET_SIGNALS has two IN payload bytes */
|
/* CMD_GET_SIGNALS has two IN payload bytes */
|
||||||
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_IN);
|
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_IN);
|
||||||
|
|
||||||
if (ret != ERROR_OK)
|
if (ret != ERROR_OK) {
|
||||||
|
free(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return ulink_append_queue(device, cmd);
|
return ulink_append_queue(device, cmd);
|
||||||
}
|
}
|
||||||
|
@ -1094,8 +1105,10 @@ int ulink_append_set_signals_cmd(struct ulink *device, uint8_t low,
|
||||||
/* CMD_SET_SIGNALS has two OUT payload bytes and zero IN payload bytes */
|
/* CMD_SET_SIGNALS has two OUT payload bytes and zero IN payload bytes */
|
||||||
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
|
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
|
||||||
|
|
||||||
if (ret != ERROR_OK)
|
if (ret != ERROR_OK) {
|
||||||
|
free(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
cmd->payload_out[0] = low;
|
cmd->payload_out[0] = low;
|
||||||
cmd->payload_out[1] = high;
|
cmd->payload_out[1] = high;
|
||||||
|
@ -1124,8 +1137,10 @@ int ulink_append_sleep_cmd(struct ulink *device, uint32_t us)
|
||||||
/* CMD_SLEEP_US has two OUT payload bytes and zero IN payload bytes */
|
/* CMD_SLEEP_US has two OUT payload bytes and zero IN payload bytes */
|
||||||
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
|
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
|
||||||
|
|
||||||
if (ret != ERROR_OK)
|
if (ret != ERROR_OK) {
|
||||||
|
free(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
cmd->payload_out[0] = us & 0x00ff;
|
cmd->payload_out[0] = us & 0x00ff;
|
||||||
cmd->payload_out[1] = (us >> 8) & 0x00ff;
|
cmd->payload_out[1] = (us >> 8) & 0x00ff;
|
||||||
|
@ -1159,8 +1174,10 @@ int ulink_append_configure_tck_cmd(struct ulink *device, int delay_scan_in,
|
||||||
/* CMD_CONFIGURE_TCK_FREQ has five OUT payload bytes and zero
|
/* CMD_CONFIGURE_TCK_FREQ has five OUT payload bytes and zero
|
||||||
* IN payload bytes */
|
* IN payload bytes */
|
||||||
ret = ulink_allocate_payload(cmd, 5, PAYLOAD_DIRECTION_OUT);
|
ret = ulink_allocate_payload(cmd, 5, PAYLOAD_DIRECTION_OUT);
|
||||||
if (ret != ERROR_OK)
|
if (ret != ERROR_OK) {
|
||||||
|
free(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (delay_scan_in < 0)
|
if (delay_scan_in < 0)
|
||||||
cmd->payload_out[0] = 0;
|
cmd->payload_out[0] = 0;
|
||||||
|
@ -1217,8 +1234,10 @@ int ulink_append_led_cmd(struct ulink *device, uint8_t led_state)
|
||||||
|
|
||||||
/* CMD_SET_LEDS has one OUT payload byte and zero IN payload bytes */
|
/* CMD_SET_LEDS has one OUT payload byte and zero IN payload bytes */
|
||||||
ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
|
ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
|
||||||
if (ret != ERROR_OK)
|
if (ret != ERROR_OK) {
|
||||||
|
free(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
cmd->payload_out[0] = led_state;
|
cmd->payload_out[0] = led_state;
|
||||||
|
|
||||||
|
@ -1245,8 +1264,10 @@ int ulink_append_test_cmd(struct ulink *device)
|
||||||
|
|
||||||
/* CMD_TEST has one OUT payload byte and zero IN payload bytes */
|
/* CMD_TEST has one OUT payload byte and zero IN payload bytes */
|
||||||
ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
|
ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
|
||||||
if (ret != ERROR_OK)
|
if (ret != ERROR_OK) {
|
||||||
|
free(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
cmd->payload_out[0] = 0xAA;
|
cmd->payload_out[0] = 0xAA;
|
||||||
|
|
||||||
|
@ -2136,6 +2157,8 @@ static int ulink_init(void)
|
||||||
ret = ulink_usb_open(&ulink_handle);
|
ret = ulink_usb_open(&ulink_handle);
|
||||||
if (ret != ERROR_OK) {
|
if (ret != ERROR_OK) {
|
||||||
LOG_ERROR("Could not open ULINK device");
|
LOG_ERROR("Could not open ULINK device");
|
||||||
|
free(ulink_handle);
|
||||||
|
ulink_handle = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2157,6 +2180,8 @@ static int ulink_init(void)
|
||||||
ULINK_FIRMWARE_FILE, ULINK_RENUMERATION_DELAY);
|
ULINK_FIRMWARE_FILE, ULINK_RENUMERATION_DELAY);
|
||||||
if (ret != ERROR_OK) {
|
if (ret != ERROR_OK) {
|
||||||
LOG_ERROR("Could not download firmware and re-numerate ULINK");
|
LOG_ERROR("Could not download firmware and re-numerate ULINK");
|
||||||
|
free(ulink_handle);
|
||||||
|
ulink_handle = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -2186,6 +2211,8 @@ static int ulink_init(void)
|
||||||
/* Bulk IN transfer failed -> unrecoverable error condition */
|
/* Bulk IN transfer failed -> unrecoverable error condition */
|
||||||
LOG_ERROR("Cannot communicate with ULINK device. Disconnect ULINK from "
|
LOG_ERROR("Cannot communicate with ULINK device. Disconnect ULINK from "
|
||||||
"the USB port and re-connect, then re-run OpenOCD");
|
"the USB port and re-connect, then re-run OpenOCD");
|
||||||
|
free(ulink_handle);
|
||||||
|
ulink_handle = NULL;
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
#ifdef _DEBUG_USB_COMMS_
|
#ifdef _DEBUG_USB_COMMS_
|
||||||
|
|
Loading…
Reference in New Issue