summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bolte <sbolte@lavabit.com>2013-05-15 16:10:12 +0200
committerStefan Bolte <sbolte@lavabit.com>2013-05-15 16:10:12 +0200
commit1b79e51c6c864ec6e0bc059c9e6a2d7f6994204c (patch)
tree8fc5e473a8343845e802adcae0007ba3832e9792
parentd4596cb45882959e8a4c292db6955550525f0c54 (diff)
downloaddwb-1b79e51c6c864ec6e0bc059c9e6a2d7f6994204c.zip
Close open file in exar_unpack on error
-rw-r--r--tools/exar/exar.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/tools/exar/exar.c b/tools/exar/exar.c
index 44525400..991c2377 100644
--- a/tools/exar/exar.c
+++ b/tools/exar/exar.c
@@ -144,9 +144,10 @@ exar_pack(const char *path)
int
exar_unpack(const char *path, const char *dest)
{
+ int ret = -1;
char name[SZ_NAME], size[SZ_SIZE], flag, rbuf;
size_t fs;
- FILE *of, *f;
+ FILE *of, *f = NULL;
unsigned char version[SZ_VERSION] = {0}, orig_version[SZ_VERSION] = {0};
LOG(3, "Opening %s for reading\n", path);
@@ -160,7 +161,7 @@ exar_unpack(const char *path, const char *dest)
if (fread(version, 1, sizeof(version), f) != sizeof(version))
{
fprintf(stderr, "Not an exar file?\n");
- return -1;
+ goto error_out;
}
memcpy(orig_version, VERSION, sizeof(orig_version));
@@ -169,14 +170,14 @@ exar_unpack(const char *path, const char *dest)
if (strncmp((char*)version, VERSION_BASE, 5))
{
fprintf(stderr, "Not an exar file?\n");
- return -1;
+ goto error_out;
}
LOG(1, "Found version %s\n", version);
if (memcmp(version, orig_version, SZ_VERSION))
{
fprintf(stderr, "Incompatible version number\n");
- return -1;
+ goto error_out;
}
if (dest != NULL)
{
@@ -184,7 +185,7 @@ exar_unpack(const char *path, const char *dest)
if (chdir(dest) != 0)
{
perror("chdir");
- return -1;
+ goto error_out;
}
}
@@ -222,9 +223,14 @@ exar_unpack(const char *path, const char *dest)
fclose(of);
}
}
- LOG(3, "Closing %s\n", path);
- fclose(f);
- return 0;
+ ret = 0;
+error_out:
+ if (f != NULL)
+ {
+ LOG(3, "Closing %s\n", path);
+ fclose(f);
+ }
+ return ret;
}
void
exar_verbose(unsigned char v)