Fix file descriptor leak when opening invalid archives.
Also add -Wunreachable-code to the set of compiler flags, otherwise
noreturn becomes considerably less useful.
bug: https://code.google.com/p/android/issues/detail?id=171099
Change-Id: I9a95d45633c731c7046d4e4a39844d9cebfd1718
(cherrypick of 241bcf05e0e394bbf2681f359f52646dd6c707f6.)
diff --git a/fastboot/Android.mk b/fastboot/Android.mk
index 1808042..66a470a 100644
--- a/fastboot/Android.mk
+++ b/fastboot/Android.mk
@@ -25,7 +25,7 @@
LOCAL_MODULE := fastboot
LOCAL_MODULE_TAGS := debug
LOCAL_CONLYFLAGS += -std=gnu99
-LOCAL_CFLAGS += -Wall -Wextra -Werror
+LOCAL_CFLAGS += -Wall -Wextra -Werror -Wunreachable-code
LOCAL_CFLAGS += -DFASTBOOT_REVISION='"$(fastboot_version)"'
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 5ad55d4..0f9d03a 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -721,12 +721,14 @@
ZipArchiveHandle zip;
int error = OpenArchive(filename, &zip);
if (error != 0) {
+ CloseArchive(zip);
die("failed to open zip file '%s': %s", filename, ErrorCodeString(error));
}
unsigned sz;
void* data = unzip_file(zip, "android-info.txt", &sz);
if (data == 0) {
+ CloseArchive(zip);
die("update package '%s' has no android-info.txt", filename);
}
@@ -738,6 +740,7 @@
if (images[i].is_optional) {
continue;
}
+ CloseArchive(zip);
exit(1); // unzip_to_file already explained why.
}
fastboot_buffer buf;
diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h
index 1786e49..481c501 100644
--- a/fastboot/fastboot.h
+++ b/fastboot/fastboot.h
@@ -69,7 +69,7 @@
/* util stuff */
double now();
char *mkmsg(const char *fmt, ...);
-void die(const char *fmt, ...);
+__attribute__((__noreturn__)) void die(const char *fmt, ...);
void get_my_path(char *path);