mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Fix leak of temporary files: if prepare_build_program_table_file()
is called in no dry-run mode and there was an error then the file
@filename will not be deleted in free_bootloader()).
Fix leak of renamed files as well as corruption of previously
created bootmap files with the same name in case of unsuccessful
IPL installation.
Add a special flag to keep a track of file's "temporary" state;
Base the cleanup decision on this flag instead of checking dry-run;
Release resources captured by prepare_bootloader() in the error path;
Move the final rename to be called only after successful installation.
Original logic:
prepare_bootloader_ipl():
prepare_bootloader_ngdump():
always create temporary @filename
if (!dry-run) rename @filename;
install;
cleanup: if (dry_run) drop @filename (*** LEAK ***)
prepare_bootloader_device():
if (dry_run) create temporary @filename
install, don't rename;
cleanup: if (dry_run) drop @filename
New logic:
prepare_bootloader_ipl():
prepare_bootloader_ngdump():
always create temporary @filename and set @tmp_filename_created;
install;
if (!dry_run) rename @filename and clear @tmp_filename_created;
cleanup: if (@tmp_filename_created is set), drop @filename
prepare_bootloader_device():
if (dry_run) create @filename and set @tmp_filename_created;
install, don't rename;
cleanup: if (@tmp_filename_created is set) drop @filename.
Fixes: https://github.com/ibm-s390-tools/s390-tools/issues/165
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Acked-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>