Fixes trying to close an invalid flash map handle
This error was catched by Coverity and it happens when a fail occurs
opening a flash map handle, which is not checked by the close
routine.
Right now this only affects Zephyr, but extra checking was added
assuming that in a future Mynewt implementation close could actually
be changed to do something.
Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index 2b0002f..ca78c6e 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -745,8 +745,12 @@
rc = 0;
done:
- flash_area_close(fap_src);
- flash_area_close(fap_dst);
+ if (fap_src) {
+ flash_area_close(fap_src);
+ }
+ if (fap_dst) {
+ flash_area_close(fap_dst);
+ }
return rc;
}