From cf77040e1e435b9bd6e1d35cd5fc6ad874703d16 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sat, 4 Apr 2015 20:50:37 +0300 Subject: [PATCH] flash/nor/lpc2000: properly free working area used in get_lpc2000_part_id() The IAP working area needs to be freed here, just like in all the other driver functions since an automatic local variable is used to store a pointer to it. This was reported by quitte (Jonas Meyer) on IRC as a strange totally unrelated segfault after doing certain operations (leading to target reset) from GDB. He has provided me with remote access to the specific machine and configuration that exposed the issue, and after some debugging it became apparent that a auto local variable (holding the gdb connection pointer) gets overwritten somehow. Placing an appropriate breakpoint just before the event and using a watchpoint made the cause apparent: reset lead to freeing of all working areas, and there was one holding a pointer to a variable that was auto local in get_lpc2000_part_id(). Change-Id: I7e634d890135ca0f3b4b311e09e8385a03982bd6 Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/2695 Tested-by: jenkins --- src/flash/nor/lpc2000.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/flash/nor/lpc2000.c b/src/flash/nor/lpc2000.c index 18085432..15d9eb81 100644 --- a/src/flash/nor/lpc2000.c +++ b/src/flash/nor/lpc2000.c @@ -1207,6 +1207,9 @@ static int get_lpc2000_part_id(struct flash_bank *bank, uint32_t *part_id) firmwares, so ignore it. */ lpc2000_iap_call(bank, iap_working_area, 54, param_table, result_table); + struct target *target = bank->target; + target_free_working_area(target, iap_working_area); + /* If the result is zero, the command probably didn't work out. */ if (result_table[0] == 0) return LPC2000_INVALID_COMMAND; -- 2.39.5