output/codeview.c: use list_for_each_safe() to free a list

Using list_for_each() is by definition not safe when freeing the
members of the list, use list_for_each_free() instead.

Also, use nasm_new() and nasm_free() where appropriate.

This was discovered as a downstream bug from BR 3392707.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2020-07-30 17:06:24 -07:00
parent bae6b070ff
commit 78df8828a0

View file

@ -305,7 +305,7 @@ static void build_type_table(struct coff_Section *const sect);
static void cv8_cleanup(void)
{
struct cv8_symbol *sym;
struct source_file *file;
struct source_file *file, *ftmp;
struct coff_Section *symbol_sect = coff_sects[cv8_state.symbol_sect];
struct coff_Section *type_sect = coff_sects[cv8_state.type_sect];
@ -316,10 +316,10 @@ static void cv8_cleanup(void)
build_symbol_table(symbol_sect);
build_type_table(type_sect);
list_for_each(file, cv8_state.source_files) {
list_for_each_safe(file, ftmp, cv8_state.source_files) {
nasm_free(file->fullname);
saa_free(file->lines);
free(file);
nasm_free(file);
}
hash_free(&cv8_state.file_hash);
@ -398,8 +398,7 @@ static struct source_file *register_file(const char *filename)
fullpath = nasm_realpath(filename);
file = nasm_zalloc(sizeof(*file));
nasm_new(file);
file->filename = filename;
file->fullname = fullpath;
file->fullnamelen = strlen(fullpath);