jtag: avoid checking for non NULL pointer to free it
The function free() can be called with a NULL pointer as argument, no need to check the argument before. If the pointer is NULL, no operation is performed by free(). Remove the occurrences of pattern: if (ptr) free(ptr); Change-Id: I2938e333bd1eac5218bd67aefb9d8f373da017a8 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5810 Tested-by: jenkins
This commit is contained in:
parent
a098a14eb5
commit
24db985f60
|
@ -2537,15 +2537,9 @@ static int aice_usb_close(void)
|
||||||
{
|
{
|
||||||
jtag_libusb_close(aice_handler.usb_handle);
|
jtag_libusb_close(aice_handler.usb_handle);
|
||||||
|
|
||||||
if (custom_srst_script)
|
free(custom_srst_script);
|
||||||
free(custom_srst_script);
|
free(custom_trst_script);
|
||||||
|
free(custom_restart_script);
|
||||||
if (custom_trst_script)
|
|
||||||
free(custom_trst_script);
|
|
||||||
|
|
||||||
if (custom_restart_script)
|
|
||||||
free(custom_restart_script);
|
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -370,8 +370,7 @@ static int amt_jtagaccel_execute_queue(void)
|
||||||
amt_jtagaccel_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
amt_jtagaccel_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
||||||
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
||||||
retval = ERROR_JTAG_QUEUE_FAILED;
|
retval = ERROR_JTAG_QUEUE_FAILED;
|
||||||
if (buffer)
|
free(buffer);
|
||||||
free(buffer);
|
|
||||||
break;
|
break;
|
||||||
case JTAG_SLEEP:
|
case JTAG_SLEEP:
|
||||||
LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
|
LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
|
||||||
|
|
|
@ -664,8 +664,7 @@ static int armjtagew_tap_execute(void)
|
||||||
return ERROR_JTAG_QUEUE_FAILED;
|
return ERROR_JTAG_QUEUE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pending_scan_result->buffer != NULL)
|
free(pending_scan_result->buffer);
|
||||||
free(pending_scan_result->buffer);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d",
|
LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d",
|
||||||
|
|
|
@ -358,8 +358,7 @@ int bitbang_execute_queue(void)
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
||||||
retval = ERROR_JTAG_QUEUE_FAILED;
|
retval = ERROR_JTAG_QUEUE_FAILED;
|
||||||
if (buffer)
|
free(buffer);
|
||||||
free(buffer);
|
|
||||||
break;
|
break;
|
||||||
case JTAG_SLEEP:
|
case JTAG_SLEEP:
|
||||||
LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
|
LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
|
||||||
|
|
|
@ -352,10 +352,8 @@ static int buspirate_quit(void)
|
||||||
|
|
||||||
buspirate_serial_close(buspirate_fd);
|
buspirate_serial_close(buspirate_fd);
|
||||||
|
|
||||||
if (buspirate_port) {
|
free(buspirate_port);
|
||||||
free(buspirate_port);
|
buspirate_port = NULL;
|
||||||
buspirate_port = NULL;
|
|
||||||
}
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -886,8 +886,7 @@ static int syncbb_execute_queue(void)
|
||||||
syncbb_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
syncbb_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
||||||
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
||||||
retval = ERROR_JTAG_QUEUE_FAILED;
|
retval = ERROR_JTAG_QUEUE_FAILED;
|
||||||
if (buffer)
|
free(buffer);
|
||||||
free(buffer);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JTAG_SLEEP:
|
case JTAG_SLEEP:
|
||||||
|
|
|
@ -709,8 +709,7 @@ static int ftdi_quit(void)
|
||||||
COMMAND_HANDLER(ftdi_handle_device_desc_command)
|
COMMAND_HANDLER(ftdi_handle_device_desc_command)
|
||||||
{
|
{
|
||||||
if (CMD_ARGC == 1) {
|
if (CMD_ARGC == 1) {
|
||||||
if (ftdi_device_desc)
|
free(ftdi_device_desc);
|
||||||
free(ftdi_device_desc);
|
|
||||||
ftdi_device_desc = strdup(CMD_ARGV[0]);
|
ftdi_device_desc = strdup(CMD_ARGV[0]);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("expected exactly one argument to ftdi_device_desc <description>");
|
LOG_ERROR("expected exactly one argument to ftdi_device_desc <description>");
|
||||||
|
@ -722,8 +721,7 @@ COMMAND_HANDLER(ftdi_handle_device_desc_command)
|
||||||
COMMAND_HANDLER(ftdi_handle_serial_command)
|
COMMAND_HANDLER(ftdi_handle_serial_command)
|
||||||
{
|
{
|
||||||
if (CMD_ARGC == 1) {
|
if (CMD_ARGC == 1) {
|
||||||
if (ftdi_serial)
|
free(ftdi_serial);
|
||||||
free(ftdi_serial);
|
|
||||||
ftdi_serial = strdup(CMD_ARGV[0]);
|
ftdi_serial = strdup(CMD_ARGV[0]);
|
||||||
} else {
|
} else {
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
|
|
|
@ -327,8 +327,7 @@ static int gw16012_execute_queue(void)
|
||||||
gw16012_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
gw16012_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
||||||
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
||||||
retval = ERROR_JTAG_QUEUE_FAILED;
|
retval = ERROR_JTAG_QUEUE_FAILED;
|
||||||
if (buffer)
|
free(buffer);
|
||||||
free(buffer);
|
|
||||||
break;
|
break;
|
||||||
case JTAG_SLEEP:
|
case JTAG_SLEEP:
|
||||||
LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
|
LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
|
||||||
|
|
|
@ -23,8 +23,7 @@ void jtag_usb_set_location(const char *location)
|
||||||
JTAG_USB_MAX_LOCATION_LENGTH)
|
JTAG_USB_MAX_LOCATION_LENGTH)
|
||||||
LOG_WARNING("usb location string is too long!!\n");
|
LOG_WARNING("usb location string is too long!!\n");
|
||||||
|
|
||||||
if (jtag_usb_location)
|
free(jtag_usb_location);
|
||||||
free(jtag_usb_location);
|
|
||||||
|
|
||||||
jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGTH);
|
jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
|
@ -439,8 +439,7 @@ static int jtag_vpi_scan(struct scan_command *cmd)
|
||||||
if (retval != ERROR_OK)
|
if (retval != ERROR_OK)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
if (buf)
|
free(buf);
|
||||||
free(buf);
|
|
||||||
|
|
||||||
if (cmd->end_state != TAP_DRSHIFT) {
|
if (cmd->end_state != TAP_DRSHIFT) {
|
||||||
retval = jtag_vpi_state_move(cmd->end_state);
|
retval = jtag_vpi_state_move(cmd->end_state);
|
||||||
|
|
|
@ -227,18 +227,11 @@ static int kitprog_quit(void)
|
||||||
{
|
{
|
||||||
kitprog_usb_close();
|
kitprog_usb_close();
|
||||||
|
|
||||||
if (kitprog_handle->packet_buffer != NULL)
|
free(kitprog_handle->packet_buffer);
|
||||||
free(kitprog_handle->packet_buffer);
|
free(kitprog_handle->serial);
|
||||||
if (kitprog_handle->serial != NULL)
|
free(kitprog_handle);
|
||||||
free(kitprog_handle->serial);
|
free(kitprog_serial);
|
||||||
if (kitprog_handle != NULL)
|
free(pending_transfers);
|
||||||
free(kitprog_handle);
|
|
||||||
|
|
||||||
if (kitprog_serial != NULL)
|
|
||||||
free(kitprog_serial);
|
|
||||||
|
|
||||||
if (pending_transfers != NULL)
|
|
||||||
free(pending_transfers);
|
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,13 +404,10 @@ void mpsse_close(struct mpsse_ctx *ctx)
|
||||||
if (ctx->usb_ctx)
|
if (ctx->usb_ctx)
|
||||||
libusb_exit(ctx->usb_ctx);
|
libusb_exit(ctx->usb_ctx);
|
||||||
bit_copy_discard(&ctx->read_queue);
|
bit_copy_discard(&ctx->read_queue);
|
||||||
if (ctx->write_buffer)
|
|
||||||
free(ctx->write_buffer);
|
|
||||||
if (ctx->read_buffer)
|
|
||||||
free(ctx->read_buffer);
|
|
||||||
if (ctx->read_chunk)
|
|
||||||
free(ctx->read_chunk);
|
|
||||||
|
|
||||||
|
free(ctx->write_buffer);
|
||||||
|
free(ctx->read_buffer);
|
||||||
|
free(ctx->read_chunk);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -386,25 +386,17 @@ static int opendous_quit(void)
|
||||||
{
|
{
|
||||||
opendous_usb_close(opendous_jtag_handle);
|
opendous_usb_close(opendous_jtag_handle);
|
||||||
|
|
||||||
if (usb_out_buffer) {
|
free(usb_out_buffer);
|
||||||
free(usb_out_buffer);
|
usb_out_buffer = NULL;
|
||||||
usb_out_buffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usb_in_buffer) {
|
free(usb_in_buffer);
|
||||||
free(usb_in_buffer);
|
usb_in_buffer = NULL;
|
||||||
usb_in_buffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pending_scan_results_buffer) {
|
free(pending_scan_results_buffer);
|
||||||
free(pending_scan_results_buffer);
|
pending_scan_results_buffer = NULL;
|
||||||
pending_scan_results_buffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opendous_type) {
|
free(opendous_type);
|
||||||
free(opendous_type);
|
opendous_type = NULL;
|
||||||
opendous_type = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
@ -697,8 +689,7 @@ int opendous_tap_execute(void)
|
||||||
return ERROR_JTAG_QUEUE_FAILED;
|
return ERROR_JTAG_QUEUE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pending_scan_result->buffer != NULL)
|
free(pending_scan_result->buffer);
|
||||||
free(pending_scan_result->buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
opendous_tap_init();
|
opendous_tap_init();
|
||||||
|
|
|
@ -591,8 +591,7 @@ static int openjtag_execute_tap_queue(void)
|
||||||
#endif
|
#endif
|
||||||
jtag_read_buffer(buffer, openjtag_scan_result_buffer[res_count].command);
|
jtag_read_buffer(buffer, openjtag_scan_result_buffer[res_count].command);
|
||||||
|
|
||||||
if (openjtag_scan_result_buffer[res_count].buffer)
|
free(openjtag_scan_result_buffer[res_count].buffer);
|
||||||
free(openjtag_scan_result_buffer[res_count].buffer);
|
|
||||||
|
|
||||||
res_count++;
|
res_count++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,10 +392,8 @@ static int parport_quit(void)
|
||||||
parport_write_data();
|
parport_write_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parport_cable) {
|
free(parport_cable);
|
||||||
free(parport_cable);
|
parport_cable = NULL;
|
||||||
parport_cable = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -511,8 +511,7 @@ static char *presto_serial;
|
||||||
COMMAND_HANDLER(presto_handle_serial_command)
|
COMMAND_HANDLER(presto_handle_serial_command)
|
||||||
{
|
{
|
||||||
if (CMD_ARGC == 1) {
|
if (CMD_ARGC == 1) {
|
||||||
if (presto_serial)
|
free(presto_serial);
|
||||||
free(presto_serial);
|
|
||||||
presto_serial = strdup(CMD_ARGV[0]);
|
presto_serial = strdup(CMD_ARGV[0]);
|
||||||
} else
|
} else
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
|
@ -553,10 +552,8 @@ static int presto_jtag_quit(void)
|
||||||
presto_close();
|
presto_close();
|
||||||
LOG_INFO("PRESTO closed");
|
LOG_INFO("PRESTO closed");
|
||||||
|
|
||||||
if (presto_serial) {
|
free(presto_serial);
|
||||||
free(presto_serial);
|
presto_serial = NULL;
|
||||||
presto_serial = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -662,14 +662,9 @@ static int icdi_usb_close(void *handle)
|
||||||
if (h->usb_ctx)
|
if (h->usb_ctx)
|
||||||
libusb_exit(h->usb_ctx);
|
libusb_exit(h->usb_ctx);
|
||||||
|
|
||||||
if (h->read_buffer)
|
free(h->read_buffer);
|
||||||
free(h->read_buffer);
|
free(h->write_buffer);
|
||||||
|
|
||||||
if (h->write_buffer)
|
|
||||||
free(h->write_buffer);
|
|
||||||
|
|
||||||
free(handle);
|
free(handle);
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -736,8 +736,7 @@ static int ublast_scan(struct scan_command *cmd)
|
||||||
ublast_queue_tdi(buf, scan_bits, type);
|
ublast_queue_tdi(buf, scan_bits, type);
|
||||||
|
|
||||||
ret = jtag_read_buffer(buf, cmd);
|
ret = jtag_read_buffer(buf, cmd);
|
||||||
if (buf)
|
free(buf);
|
||||||
free(buf);
|
|
||||||
/*
|
/*
|
||||||
* ublast_queue_tdi sends the last bit with TMS=1. We are therefore
|
* ublast_queue_tdi sends the last bit with TMS=1. We are therefore
|
||||||
* already in Exit1-DR/IR and have to skip the first step on our way
|
* already in Exit1-DR/IR and have to skip the first step on our way
|
||||||
|
|
|
@ -137,8 +137,7 @@ static int usbprog_execute_queue(void)
|
||||||
usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
||||||
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
||||||
return ERROR_JTAG_QUEUE_FAILED;
|
return ERROR_JTAG_QUEUE_FAILED;
|
||||||
if (buffer)
|
free(buffer);
|
||||||
free(buffer);
|
|
||||||
break;
|
break;
|
||||||
case JTAG_SLEEP:
|
case JTAG_SLEEP:
|
||||||
LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
|
LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
|
||||||
|
|
|
@ -299,14 +299,11 @@ RESULT versaloon_fini(void)
|
||||||
|
|
||||||
versaloon_usb_device_handle = NULL;
|
versaloon_usb_device_handle = NULL;
|
||||||
|
|
||||||
if (versaloon_buf != NULL) {
|
free(versaloon_buf);
|
||||||
free(versaloon_buf);
|
versaloon_buf = NULL;
|
||||||
versaloon_buf = NULL;
|
|
||||||
}
|
free(versaloon_cmd_buf);
|
||||||
if (versaloon_cmd_buf != NULL) {
|
versaloon_cmd_buf = NULL;
|
||||||
free(versaloon_cmd_buf);
|
|
||||||
versaloon_cmd_buf = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
|
|
@ -245,18 +245,14 @@ static int vsllink_speed_div(int jtag_speed, int *khz)
|
||||||
|
|
||||||
static void vsllink_free_buffer(void)
|
static void vsllink_free_buffer(void)
|
||||||
{
|
{
|
||||||
if (tdi_buffer != NULL) {
|
free(tdi_buffer);
|
||||||
free(tdi_buffer);
|
tdi_buffer = NULL;
|
||||||
tdi_buffer = NULL;
|
|
||||||
}
|
free(tdo_buffer);
|
||||||
if (tdo_buffer != NULL) {
|
tdo_buffer = NULL;
|
||||||
free(tdo_buffer);
|
|
||||||
tdo_buffer = NULL;
|
free(tms_buffer);
|
||||||
}
|
tms_buffer = NULL;
|
||||||
if (tms_buffer != NULL) {
|
|
||||||
free(tms_buffer);
|
|
||||||
tms_buffer = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vsllink_quit(void)
|
static int vsllink_quit(void)
|
||||||
|
@ -676,8 +672,7 @@ static int vsllink_jtag_execute(void)
|
||||||
return ERROR_JTAG_QUEUE_FAILED;
|
return ERROR_JTAG_QUEUE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pending_scan_result->buffer != NULL)
|
free(pending_scan_result->buffer);
|
||||||
free(pending_scan_result->buffer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -282,8 +282,7 @@ static int xlnx_pcie_xvc_execute_scan(struct jtag_command *cmd)
|
||||||
};
|
};
|
||||||
|
|
||||||
err = jtag_read_buffer(buf, cmd->cmd.scan);
|
err = jtag_read_buffer(buf, cmd->cmd.scan);
|
||||||
if (buf)
|
free(buf);
|
||||||
free(buf);
|
|
||||||
|
|
||||||
if (tap_get_state() != tap_get_end_state())
|
if (tap_get_state() != tap_get_end_state())
|
||||||
err = xlnx_pcie_xvc_execute_statemove(1);
|
err = xlnx_pcie_xvc_execute_statemove(1);
|
||||||
|
@ -291,8 +290,7 @@ static int xlnx_pcie_xvc_execute_scan(struct jtag_command *cmd)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
out_err:
|
out_err:
|
||||||
if (buf)
|
free(buf);
|
||||||
free(buf);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,8 +454,7 @@ COMMAND_HANDLER(xlnx_pcie_xvc_handle_config_command)
|
||||||
* limit the memory we're leaking by freeing the old one first
|
* limit the memory we're leaking by freeing the old one first
|
||||||
* before allocating a new one ...
|
* before allocating a new one ...
|
||||||
*/
|
*/
|
||||||
if (xlnx_pcie_xvc->device)
|
free(xlnx_pcie_xvc->device);
|
||||||
free(xlnx_pcie_xvc->device);
|
|
||||||
|
|
||||||
xlnx_pcie_xvc->device = strdup(CMD_ARGV[0]);
|
xlnx_pcie_xvc->device = strdup(CMD_ARGV[0]);
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
|
|
@ -1155,10 +1155,8 @@ COMMAND_HANDLER(handle_irscan_command)
|
||||||
retval = jtag_execute_queue();
|
retval = jtag_execute_queue();
|
||||||
|
|
||||||
error_return:
|
error_return:
|
||||||
for (i = 0; i < num_fields; i++) {
|
for (i = 0; i < num_fields; i++)
|
||||||
if (NULL != fields[i].out_value)
|
free((void *)fields[i].out_value);
|
||||||
free((void *)fields[i].out_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(fields);
|
free(fields);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue