case PAYLOAD_DIRECTION_OUT:
if (ulink_cmd->payload_out != NULL) {
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
+ free(payload);
return ERROR_FAIL;
} else {
ulink_cmd->payload_out = payload;
case PAYLOAD_DIRECTION_IN:
if (ulink_cmd->payload_in_start != NULL) {
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
+ free(payload);
return ERROR_FAIL;
} else {
ulink_cmd->payload_in_start = payload;
if (scan_size_bits > (58 * 8)) {
LOG_ERROR("BUG: Tried to create CMD_SCAN_IO OpenULINK command with too"
" large payload");
+ free(cmd);
return ERROR_FAIL;
}
break;
}
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
/* Build payload_out that is common to all scan types */
cmd->payload_out[0] = scan_size_bytes & 0xFF;
/* CMD_CLOCK_TMS has two OUT payload bytes and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = count;
cmd->payload_out[1] = sequence;
/* CMD_CLOCK_TCK has two OUT payload bytes and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = count & 0xff;
cmd->payload_out[1] = (count >> 8) & 0xff;
/* CMD_GET_SIGNALS has two IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_IN);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
return ulink_append_queue(device, cmd);
}
/* CMD_SET_SIGNALS has two OUT payload bytes and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = low;
cmd->payload_out[1] = high;
/* CMD_SLEEP_US has two OUT payload bytes and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = us & 0x00ff;
cmd->payload_out[1] = (us >> 8) & 0x00ff;
/* CMD_CONFIGURE_TCK_FREQ has five OUT payload bytes and zero
* IN payload bytes */
ret = ulink_allocate_payload(cmd, 5, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
if (delay_scan_in < 0)
cmd->payload_out[0] = 0;
/* CMD_SET_LEDS has one OUT payload byte and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = led_state;
/* CMD_TEST has one OUT payload byte and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = 0xAA;
ret = ulink_usb_open(&ulink_handle);
if (ret != ERROR_OK) {
LOG_ERROR("Could not open ULINK device");
+ free(ulink_handle);
+ ulink_handle = NULL;
return ret;
}
ULINK_FIRMWARE_FILE, ULINK_RENUMERATION_DELAY);
if (ret != ERROR_OK) {
LOG_ERROR("Could not download firmware and re-numerate ULINK");
+ free(ulink_handle);
+ ulink_handle = NULL;
return ret;
}
} else
/* Bulk IN transfer failed -> unrecoverable error condition */
LOG_ERROR("Cannot communicate with ULINK device. Disconnect ULINK from "
"the USB port and re-connect, then re-run OpenOCD");
+ free(ulink_handle);
+ ulink_handle = NULL;
return ERROR_FAIL;
}
#ifdef _DEBUG_USB_COMMS_