[PATCH]: fef7f85385 target/esirisc: free memory at OpenOCD exit

2024-01-14 Thread gerrit
This is an automated email from Gerrit.

"Antonio Borneo " just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8094

-- gerrit

commit fef7f853851dd214e49c2e2610b932f3f044c83b
Author: Antonio Borneo 
Date:   Sun Jan 14 17:51:41 2024 +0100

target/esirisc: free memory at OpenOCD exit

The target esirisc does not free the allocated memory resources,
causing memory leaks at OpenOCD exit.

Add esirisc_free_reg_cache() and esirisc_deinit_target() and use
them to free all the allocated resources.

Change-Id: I17b8ebff54906fa25a37f2d96c01d010a98cffbd
Signed-off-by: Antonio Borneo 

diff --git a/src/target/esirisc.c b/src/target/esirisc.c
index 561edb255a..8889f48b34 100644
--- a/src/target/esirisc.c
+++ b/src/target/esirisc.c
@@ -1486,6 +1486,32 @@ static struct reg_cache *esirisc_build_reg_cache(struct 
target *target)
return cache;
 }
 
+static void esirisc_free_reg_cache(struct target *target)
+{
+   struct esirisc_common *esirisc = target_to_esirisc(target);
+   struct reg_cache *cache = esirisc->reg_cache;
+   struct reg *reg_list = cache->reg_list;
+
+   for (int i = 0; i < esirisc->num_regs; ++i) {
+   struct reg *reg = reg_list + esirisc_regs[i].number;
+
+   free(reg->arch_info);
+   free(reg->value);
+   free(reg->reg_data_type);
+   }
+
+   for (size_t i = 0; i < ARRAY_SIZE(esirisc_csrs); ++i) {
+   struct reg *reg = reg_list + esirisc_csrs[i].number;
+
+   free(reg->arch_info);
+   free(reg->value);
+   free(reg->reg_data_type);
+   }
+
+   free(reg_list);
+   free(cache);
+}
+
 static int esirisc_identify(struct target *target)
 {
struct esirisc_common *esirisc = target_to_esirisc(target);
@@ -1584,6 +1610,19 @@ static int esirisc_init_target(struct command_context 
*cmd_ctx, struct target *t
return ERROR_OK;
 }
 
+static void esirisc_deinit_target(struct target *target)
+{
+   struct esirisc_common *esirisc = target_to_esirisc(target);
+
+   if (!target_was_examined(target))
+   return;
+
+   esirisc_free_reg_cache(target);
+
+   free(esirisc->gdb_arch);
+   free(esirisc);
+}
+
 static int esirisc_examine(struct target *target)
 {
struct esirisc_common *esirisc = target_to_esirisc(target);
@@ -1822,5 +1861,6 @@ struct target_type esirisc_target = {
 
.target_create = esirisc_target_create,
.init_target = esirisc_init_target,
+   .deinit_target = esirisc_deinit_target,
.examine = esirisc_examine,
 };

-- 



Re: Character conflict in the remote-bitbnag protocol

2024-01-14 Thread Antonio Borneo
I don't think there is any preference.
You are the first to implement this remote delay, so any character
currently unused can do the job

Thanks
Antonio

On Sun, Jan 14, 2024 at 12:00 AM Jeremy Herbert  wrote:
>
> Hi all,
>
> No problems, happy to change to whatever you think is best.
>
> Thanks,
> Jeremy
>
> On Sun, 14 Jan 2024 at 4:58 am, Tommy Murphy  wrote:
>>
>> > Tommy, thanks for the alert.
>>
>> Just to clarify, it was Marek who flagged the issue.
>> I just linked to the documentation for the conflicting 'd' requests to give 
>> some additional context. :⁠-⁠)