Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rimage: elf_file: Fix elf_free behavior on unopened elf file #8530

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions tools/rimage/src/elf_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,7 @@ int elf_open(struct elf_file *elf, const char *filename)
return 0;

err:
free(elf->filename);
free(elf->programs);

if (elf->file)
fclose(elf->file);

if (elf->sections) {
for (int i = 0; i < elf->sections_count; i++)
elf_section_header_free(&elf->sections[i]);

free(elf->sections);
}
elf_free(elf);

return ret;
}
Expand All @@ -436,13 +425,17 @@ void elf_free(struct elf_file *elf)
int i;

free(elf->filename);
fclose(elf->file);
free(elf->programs);

for (i = 0; i < elf->sections_count; i++)
elf_section_header_free(&elf->sections[i]);
if (elf->file)
fclose(elf->file);

free(elf->sections);
free(elf->programs);
if (elf->sections) {
for (i = 0; i < elf->sections_count; i++)
elf_section_header_free(&elf->sections[i]);

free(elf->sections);
}
}

int elf_section_read_content(const struct elf_file *elf, const struct elf_section_header *header,
Expand Down
2 changes: 1 addition & 1 deletion tools/rimage/src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int module_write_whole_elf(const struct module *module, FILE *out_file, const ch
/* write out section data */
count = fwrite(buffer, module->elf.file_size, 1, out_file);
if (count != 1) {
ret = file_error("can't write data", "");// TODO: image->out_file);
ret = file_error("can't write data", filename);
goto out;
}

Expand Down