diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2009-12-05 14:04:55 +0300 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2009-12-05 14:10:41 +0300 |
commit | 6531d6d159af0d51e519c0305843bed03c77d97b (patch) | |
tree | 64fc244dbe44ed40db72d6b2d9d5bbbd4ea27480 /assemble.c | |
parent | 416bd78bae87641b3da48349c55d9e7f3b193ff4 (diff) | |
download | nasm-6531d6d159af0d51e519c0305843bed03c77d97b.tar.gz nasm-6531d6d159af0d51e519c0305843bed03c77d97b.tar.bz2 nasm-6531d6d159af0d51e519c0305843bed03c77d97b.zip |
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.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -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 */ |