diff options
author | Tomas Vanek <vanekt@fbl.cz> | 2021-11-18 09:37:23 +0100 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2021-12-03 21:59:20 +0000 |
commit | f735faa9319af324b94e4257444419c8dfec6592 (patch) | |
tree | 1d42acd12cc96d37e19b278d17926c6f2e1e98c3 /src/target/target.c | |
parent | 35f284fe7c51d29768156cfec172152d2539d98a (diff) | |
download | riscv-openocd-f735faa9319af324b94e4257444419c8dfec6592.zip riscv-openocd-f735faa9319af324b94e4257444419c8dfec6592.tar.gz riscv-openocd-f735faa9319af324b94e4257444419c8dfec6592.tar.bz2 |
target,flash: allow target_free_working_area on NULL area pointer
Standard C library free() allows NULL pointer as a parameter.
Change target_free_working_area() to conform this convention.
Remove NULL pointer tests before target_free_working_area() calls.
While on it add missing setting pointer to NULL after target_free_working_area().
Change-Id: I7c692ab04a9933398ba5bc614723ad0bdecb87b3
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6712
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src/target/target.c')
-rw-r--r-- | src/target/target.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/target/target.c b/src/target/target.c index ed6f655..27888a8 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2148,11 +2148,10 @@ static int target_restore_working_area(struct target *target, struct working_are /* Restore the area's backup memory, if any, and return the area to the allocation pool */ static int target_free_working_area_restore(struct target *target, struct working_area *area, int restore) { - int retval = ERROR_OK; - - if (area->free) - return retval; + if (!area || area->free) + return ERROR_OK; + int retval = ERROR_OK; if (restore) { retval = target_restore_working_area(target, area); /* REVISIT: Perhaps the area should be freed even if restoring fails. */ @@ -6401,8 +6400,7 @@ next: out: free(test_pattern); - if (wa) - target_free_working_area(target, wa); + target_free_working_area(target, wa); /* Test writes */ num_bytes = test_size + 4 + 4 + 4; @@ -6486,8 +6484,7 @@ nextw: free(test_pattern); - if (wa) - target_free_working_area(target, wa); + target_free_working_area(target, wa); return retval; } |