]> git.sur5r.net Git - openocd/commitdiff
jtag/core, target: unregister JTAG events
authorTomas Vanek <vanekt@fbl.cz>
Wed, 21 Mar 2018 23:20:15 +0000 (00:20 +0100)
committerMatthias Welwarsky <matthias@welwarsky.de>
Fri, 30 Mar 2018 09:15:23 +0000 (10:15 +0100)
Also call adapter_exit() before command_exit() as the latter releases
Jim interpreter so JTAG events should be released before.

Fixes memory leak reported by valgrind

Change-Id: I493f3fcba34ea2b4234148e79a4e329c866e0f05
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4474
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
src/jtag/core.c
src/openocd.c
src/target/target.c

index 0fbd327fe6ece8c3d674fd98a4ad5d3f46ecf834..4522321a7ace45eb0bb64a206ce63aaea0cfaa4d 100644 (file)
@@ -1308,6 +1308,14 @@ void jtag_tap_free(struct jtag_tap *tap)
 {
        jtag_unregister_event_callback(&jtag_reset_callback, tap);
 
+       struct jtag_tap_event_action *jteap = tap->event_action;
+       while (jteap) {
+               struct jtag_tap_event_action *next = jteap->next;
+               Jim_DecrRefCount(jteap->interp, jteap->body);
+               free(jteap);
+               jteap = next;
+       }
+
        free(tap->expected);
        free(tap->expected_mask);
        free(tap->expected_ids);
index d5d7ebe8768211c97a81caa6320520cf73c65ee6..902528d08b889d314a89db3f66c603b22c591547 100644 (file)
@@ -359,11 +359,11 @@ int openocd_main(int argc, char *argv[])
 
        unregister_all_commands(cmd_ctx, NULL);
 
+       adapter_quit();
+
        /* Shutdown commandline interface */
        command_exit(cmd_ctx);
 
-       adapter_quit();
-
        free_config();
 
        if (ERROR_FAIL == ret)
index 10426023a47c3c5ef1580051e5d9dc0e1bc706d5..ac2e1d030abed103e52c9de79e20aafb945ddd6e 100644 (file)
@@ -1893,6 +1893,8 @@ static void target_destroy(struct target *target)
        if (target->type->deinit_target)
                target->type->deinit_target(target);
 
+       jtag_unregister_event_callback(jtag_enable_callback, target);
+
        struct target_event_action *teap = target->event_action;
        while (teap) {
                struct target_event_action *next = teap->next;