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

@@ -1072,7 +1072,7 @@ static int mips_m4k_read_memory(struct target *target, target_addr_t address,
}
}
if ((size > 1) && (t != NULL))
if (size > 1)
free(t);
return retval;
@@ -1135,8 +1135,7 @@ static int mips_m4k_write_memory(struct target *target, target_addr_t address,
else
retval = mips32_dmaacc_write_mem(ejtag_info, address, size, count, buffer);
if (t != NULL)
free(t);
free(t);
if (ERROR_OK != retval)
return retval;
@@ -1261,8 +1260,7 @@ static int mips_m4k_bulk_write_memory(struct target *target, target_addr_t addre
retval = mips32_pracc_fastdata_xfer(ejtag_info, mips32->fast_data_area, write_t, address,
count, t);
if (t != NULL)
free(t);
free(t);
if (retval != ERROR_OK)
LOG_ERROR("Fastdata access Failed");