Merge pull request #260 from dlrobertson/fix_segfault
Fix posible null deref in get_target_typeriscv-compliance-dev^2
commit
6875379089
|
@ -232,6 +232,11 @@ static struct target_type *get_target_type(struct target *target)
|
||||||
{
|
{
|
||||||
riscv_info_t *info = (riscv_info_t *) target->arch_info;
|
riscv_info_t *info = (riscv_info_t *) target->arch_info;
|
||||||
|
|
||||||
|
if (!info) {
|
||||||
|
LOG_ERROR("Target has not been initialized");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
switch (info->dtm_version) {
|
switch (info->dtm_version) {
|
||||||
case 0:
|
case 0:
|
||||||
return &riscv011_target;
|
return &riscv011_target;
|
||||||
|
@ -265,9 +270,11 @@ static void riscv_deinit_target(struct target *target)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("riscv_deinit_target()");
|
LOG_DEBUG("riscv_deinit_target()");
|
||||||
struct target_type *tt = get_target_type(target);
|
struct target_type *tt = get_target_type(target);
|
||||||
tt->deinit_target(target);
|
if (tt) {
|
||||||
riscv_info_t *info = (riscv_info_t *) target->arch_info;
|
tt->deinit_target(target);
|
||||||
free(info);
|
riscv_info_t *info = (riscv_info_t *) target->arch_info;
|
||||||
|
free(info);
|
||||||
|
}
|
||||||
target->arch_info = NULL;
|
target->arch_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue