mtdutils: restore_raw_partition: remove rouge file descriptor
*call to open() was replaced with fopen() and should have been removed.
*move call to fopen() to safer location where it will be closed before
potential return.
Change-Id: I4f40b3a673c1612a229af30881973e100388ca47
diff --git a/mtdutils/mtdutils.c b/mtdutils/mtdutils.c
index a76b8e9..e401a68 100644
--- a/mtdutils/mtdutils.c
+++ b/mtdutils/mtdutils.c
@@ -573,12 +573,6 @@
MtdWriteContext *write;
void *data;
- FILE* f = fopen(filename, "rb");
- if (f == NULL) {
- fprintf(stderr, "error opening %s", filename);
- return -1;
- }
-
if (mtd_scan_partitions() <= 0)
{
fprintf(stderr, "error scanning partitions");
@@ -591,19 +585,18 @@
return -1;
}
- int fd = open(filename, O_RDONLY);
- if (fd < 0)
- {
- printf("error opening %s", filename);
- return -1;
- }
-
MtdWriteContext* ctx = mtd_write_partition(mtd);
if (ctx == NULL) {
printf("error writing %s", partition_name);
return -1;
}
+ FILE* f = fopen(filename, "rb");
+ if (f == NULL) {
+ fprintf(stderr, "error opening %s", filename);
+ return -1;
+ }
+
int success = 1;
char* buffer = malloc(BUFSIZ);
int read;