diff --git a/stable/mips64.c b/stable/mips64.c index 6ea30f366..ad194ecb7 100644 --- a/stable/mips64.c +++ b/stable/mips64.c @@ -938,17 +938,21 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load, if (elf_version(EV_CURRENT) == EV_NONE) { fprintf(stderr,"load_elf_image: library out of date\n"); + close(fd); return(-1); } if (!(img_elf = elf_begin(fd,ELF_C_READ,NULL))) { fprintf(stderr,"load_elf_image: elf_begin: %s\n", elf_errmsg(elf_errno())); + close(fd); return(-1); } if (!(ehdr = elf32_getehdr(img_elf))) { fprintf(stderr,"load_elf_image: invalid ELF file\n"); + elf_end(img_elf); + close(fd); return(-1); } @@ -957,6 +961,8 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load, if (!bfd) { perror("load_elf_image: fdopen"); + elf_end(img_elf); + close(fd); return(-1); } diff --git a/unstable/mips64.c b/unstable/mips64.c index e301abcd6..99ff9293b 100644 --- a/unstable/mips64.c +++ b/unstable/mips64.c @@ -1021,17 +1021,21 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load, if (elf_version(EV_CURRENT) == EV_NONE) { fprintf(stderr,"load_elf_image: library out of date\n"); + close(fd); return(-1); } if (!(img_elf = elf_begin(fd,ELF_C_READ,NULL))) { fprintf(stderr,"load_elf_image: elf_begin: %s\n", elf_errmsg(elf_errno())); + close(fd); return(-1); } if (!(ehdr = elf32_getehdr(img_elf))) { fprintf(stderr,"load_elf_image: invalid ELF file\n"); + elf_end(img_elf); + close(fd); return(-1); } @@ -1040,6 +1044,8 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load, if (!bfd) { perror("load_elf_image: fdopen"); + elf_end(img_elf); + close(fd); return(-1); }