Skip to content

Commit 78df882

Browse files
author
H. Peter Anvin (Intel)
committed
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) <[email protected]>
1 parent bae6b07 commit 78df882

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

output/codeview.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static void build_type_table(struct coff_Section *const sect);
305305
static void cv8_cleanup(void)
306306
{
307307
struct cv8_symbol *sym;
308-
struct source_file *file;
308+
struct source_file *file, *ftmp;
309309

310310
struct coff_Section *symbol_sect = coff_sects[cv8_state.symbol_sect];
311311
struct coff_Section *type_sect = coff_sects[cv8_state.type_sect];
@@ -316,10 +316,10 @@ static void cv8_cleanup(void)
316316
build_symbol_table(symbol_sect);
317317
build_type_table(type_sect);
318318

319-
list_for_each(file, cv8_state.source_files) {
319+
list_for_each_safe(file, ftmp, cv8_state.source_files) {
320320
nasm_free(file->fullname);
321321
saa_free(file->lines);
322-
free(file);
322+
nasm_free(file);
323323
}
324324
hash_free(&cv8_state.file_hash);
325325

@@ -398,8 +398,7 @@ static struct source_file *register_file(const char *filename)
398398

399399
fullpath = nasm_realpath(filename);
400400

401-
file = nasm_zalloc(sizeof(*file));
402-
401+
nasm_new(file);
403402
file->filename = filename;
404403
file->fullname = fullpath;
405404
file->fullnamelen = strlen(fullpath);

0 commit comments

Comments
 (0)