diff options
author | Marc Schink <dev@zapb.de> | 2020-02-27 13:48:15 +0100 |
---|---|---|
committer | Tomas Vanek <vanekt@fbl.cz> | 2020-03-17 16:40:14 +0000 |
commit | aff486b6a05e1413520537d0d257e36e433754fd (patch) | |
tree | 5bd258071d957e6d0ec388c167bbdd7269f9efbe /src | |
parent | dca1c6ca1f78a6a89e4274e409ff822d655add6b (diff) | |
download | riscv-openocd-aff486b6a05e1413520537d0d257e36e433754fd.zip riscv-openocd-aff486b6a05e1413520537d0d257e36e433754fd.tar.gz riscv-openocd-aff486b6a05e1413520537d0d257e36e433754fd.tar.bz2 |
rtos: Destroy RTOS and fix memory leak
The memory leak can be reproduced by using an arbitrary RTOS
and valgrind:
$ valgrind --leak-check=full --show-leak-kinds=all
[...]
==9656== 224 (80 direct, 144 indirect) bytes in 1 blocks are definitely lost in loss record 3 of 3
==9656== at 0x483CD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==9656== by 0x1C541A: os_alloc (rtos.c:79)
==9656== by 0x1C569E: os_alloc_create (rtos.c:111)
==9656== by 0x1C569E: rtos_create (rtos.c:153)
==9656== by 0x1AE332: target_configure (target.c:4899)
==9656== by 0x1AF228: jim_target_configure (target.c:4952)
==9656== by 0x1C9EF9: command_unknown (command.c:1066)
==9656== by 0x313284: JimInvokeCommand (jim.c:10364)
==9656== by 0x313FB6: Jim_EvalObj (jim.c:10814)
==9656== by 0x3154A3: Jim_EvalFile (jim.c:11207)
==9656== by 0x316015: Jim_SourceCoreCommand (jim.c:15230)
==9656== by 0x313284: JimInvokeCommand (jim.c:10364)
==9656== by 0x313B8B: JimEvalObjList (jim.c:10605)
[...]
Change-Id: I2cd41a154fb8570842601ff4e3e76502f5908f49
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5479
Tested-by: jenkins
Reviewed-by: Moritz Fischer <moritzf@google.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Diffstat (limited to 'src')
-rw-r--r-- | src/rtos/rtos.c | 5 | ||||
-rw-r--r-- | src/rtos/rtos.h | 1 | ||||
-rw-r--r-- | src/target/target.c | 2 |
3 files changed, 8 insertions, 0 deletions
diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 002d7b5..549833f 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -159,6 +159,11 @@ int rtos_create(Jim_GetOptInfo *goi, struct target *target) return JIM_ERR; } +void rtos_destroy(struct target *target) +{ + os_free(target); +} + int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size) { struct target *target = get_target_from_connection(connection); diff --git a/src/rtos/rtos.h b/src/rtos/rtos.h index a649e24..c755eec 100644 --- a/src/rtos/rtos.h +++ b/src/rtos/rtos.h @@ -111,6 +111,7 @@ struct rtos_register_stacking { #define GDB_THREAD_PACKET_NOT_CONSUMED (-40) int rtos_create(Jim_GetOptInfo *goi, struct target *target); +void rtos_destroy(struct target *target); int rtos_set_reg(struct connection *connection, int reg_num, uint8_t *reg_value); int rtos_generic_stack_read(struct target *target, diff --git a/src/target/target.c b/src/target/target.c index ceecaee..b77400c 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2049,6 +2049,8 @@ static void target_destroy(struct target *target) target->smp = 0; } + rtos_destroy(target); + free(target->gdb_port_override); free(target->type); free(target->trace_info); |