target: 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);

In target/openrisc/jsp_server.c, an error is logged if the ptr was
already NULL. This cannot happen since the pointer was already
referenced few lines before and openocd would have been already
SIGSEGV in that case, so remove the log.

Change-Id: I290a32e6d4deab167676af4ddc83523c830ae49e
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5809
Tested-by: jenkins
This commit is contained in:
Antonio Borneo
2020-08-17 09:58:58 +02:00
parent 0dad8cbfe9
commit 3934483429
11 changed files with 43 additions and 87 deletions

View File

@@ -190,12 +190,8 @@ static int jsp_connection_closed(struct connection *connection)
if (ERROR_OK != retval)
return retval;
if (connection->priv) {
free(connection->priv);
connection->priv = NULL;
} else
LOG_ERROR("BUG: connection->priv == NULL");
free(connection->priv);
connection->priv = NULL;
return ERROR_OK;
}

View File

@@ -943,8 +943,7 @@ static int or1k_add_breakpoint(struct target *target,
return retval;
}
if (breakpoint->orig_instr != NULL)
free(breakpoint->orig_instr);
free(breakpoint->orig_instr);
breakpoint->orig_instr = malloc(breakpoint->length);
memcpy(breakpoint->orig_instr, &data, breakpoint->length);

View File

@@ -975,8 +975,7 @@ static int or1k_adv_jtag_write_memory(struct or1k_jtag *jtag_info,
size, blocks_this_round,
block_count_address);
if (retval != ERROR_OK) {
if (t != NULL)
free(t);
free(t);
return retval;
}
@@ -985,9 +984,7 @@ static int or1k_adv_jtag_write_memory(struct or1k_jtag *jtag_info,
block_count_buffer += size * MAX_BURST_SIZE;
}
if (t != NULL)
free(t);
free(t);
return ERROR_OK;
}