mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zipl/src: Fix leak of files
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>
This commit is contained in:
committed by
Steffen Eiden
parent
bc9f8a8100
commit
90a2e6d70e
+3
-4
@@ -576,10 +576,10 @@ disk_get_info_from_file(const char* filename, struct job_target_data* target,
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
disk_free_info(struct disk_info* info)
|
||||
void disk_free_info(struct disk_info *info)
|
||||
{
|
||||
if (!info)
|
||||
return;
|
||||
if (info->name)
|
||||
free(info->name);
|
||||
if (info->drv_name)
|
||||
@@ -587,7 +587,6 @@ disk_free_info(struct disk_info* info)
|
||||
free(info);
|
||||
}
|
||||
|
||||
|
||||
/* Retrieve the physical blocknumber (block on disk) of the specified logical
|
||||
* block (block in file). FD provides the file descriptor, LOGICAL is the
|
||||
* logical block number. Upon success, return 0 and store the physical
|
||||
|
||||
Reference in New Issue
Block a user