summaryrefslogtreecommitdiff
path: root/assemble.c
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2009-12-05 14:04:55 +0300
committerCyrill Gorcunov <gorcunov@gmail.com>2009-12-05 14:10:41 +0300
commit6531d6d159af0d51e519c0305843bed03c77d97b (patch)
tree64fc244dbe44ed40db72d6b2d9d5bbbd4ea27480 /assemble.c
parent416bd78bae87641b3da48349c55d9e7f3b193ff4 (diff)
downloadnasm-6531d6d159af0d51e519c0305843bed03c77d97b.tar.gz
BR2907058: insn_size - close file handle before returning
As example of such behaviour is when fseek fails for some reason. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Diffstat (limited to 'assemble.c')
-rw-r--r--assemble.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/assemble.c b/assemble.c
index 4af059b2..81476db0 100644
--- a/assemble.c
+++ b/assemble.c
@@ -687,6 +687,7 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, uint32_t cp,
if (instruction->opcode == I_INCBIN) {
const char *fname = instruction->eops->stringval;
FILE *fp;
+ int64_t val = 0;
size_t len;
fp = fopen(fname, "rb");
@@ -698,7 +699,6 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, uint32_t cp,
fname);
else {
len = ftell(fp);
- fclose(fp);
if (instruction->eops->next) {
len -= instruction->eops->next->offset;
if (instruction->eops->next->next &&
@@ -706,9 +706,11 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, uint32_t cp,
len = (size_t)instruction->eops->next->next->offset;
}
}
- return instruction->times * len;
+ val = instruction->times * len;
}
- return 0; /* if we're here, there's an error */
+ if (fp)
+ fclose(fp);
+ return val;
}
/* Check to see if we need an address-size prefix */