Skip to content

Commit

Permalink
Merge pull request #151 from flaviojs/fix-resource-leaks-mips64_load_…
Browse files Browse the repository at this point in the history
…elf_image

Fix resource leaks in mips64_load_elf_image
  • Loading branch information
grossmj authored Mar 9, 2024
2 parents 9f60d7f + 9f29ebb commit 9c889fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions stable/mips64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions unstable/mips64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 9c889fc

Please sign in to comment.