]> git.sur5r.net Git - openocd/commitdiff
flash/nor/lpc2000: free allocated working area when target_write fails
authorPaul Fertser <fercerpav@gmail.com>
Sat, 4 Apr 2015 21:16:59 +0000 (00:16 +0300)
committerPaul Fertser <fercerpav@gmail.com>
Tue, 14 Apr 2015 11:41:26 +0000 (12:41 +0100)
In some circumstances (e.g. inappropriate jtag clock)
target_write_memory in lpc2000_iap_working_area_init might fail. The
allocated working area should be freed inside
lpc2000_iap_working_area_init in this error case.

This was leading to a weird segfault due to stack corruption later
when reset was executed.

Reported by quitte (Jonas Meyer).

Change-Id: Ia2ed42a9970a4d771727fd516a6eea88e9b859e2
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2696
Tested-by: jenkins
src/flash/nor/lpc2000.c

index 15d9eb81c5c4ff29324124199fd33455946195fe..0247e66df34fde4aec9b0999ab68e18b6bffb8ab 100644 (file)
@@ -679,9 +679,11 @@ static int lpc2000_iap_working_area_init(struct flash_bank *bank, struct working
        }
 
        int retval = target_write_memory(target, (*iap_working_area)->address, 4, 2, jump_gate);
-       if (retval != ERROR_OK)
+       if (retval != ERROR_OK) {
                LOG_ERROR("Write memory at address 0x%8.8" PRIx32 " failed (check work_area definition)",
                                (*iap_working_area)->address);
+               target_free_working_area(target, *iap_working_area);
+       }
 
        return retval;
 }