safe filedescriptors

git-svn-id: svn://coreboot.org/openbios/openbios-devel@44 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Stefan Reinauer
2006-06-05 19:40:05 +00:00
parent 280a06e3d9
commit 65bae45b24
4 changed files with 15 additions and 1 deletions

View File

@@ -139,5 +139,6 @@ int aout_load(struct sys_info *info, const char *filename, const char *cmdline)
retval = 0;
out:
file_close();
return retval;
}

View File

@@ -127,6 +127,7 @@ static unsigned long process_image_notes(Elf_phdr *phdr, int phnum,
}
}
out:
file_close();
if (buf)
free(buf);
return retval;
@@ -402,6 +403,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline)
retval = 0;
out:
file_close();
if (phdr)
free(phdr);
if (boot_notes)

View File

@@ -589,8 +589,10 @@ int linux_load(struct sys_info *info, const char *file, const char *cmdline)
return -1;
kern_addr = load_linux_header(&hdr);
if (kern_addr == 0)
if (kern_addr == 0) {
file_close();
return LOADER_NOT_SUPPORT;
}
params = phys_to_virt(LINUX_PARAM_LOC);
init_linux_params(params, &hdr);

View File

@@ -13,6 +13,15 @@ int file_open(const char *filename)
return load_fd>-1;
}
void file_close(void)
{
if(load_fd==-1)
return;
close_io(load_fd);
load_fd=-1;
}
int lfile_read(void *buf, unsigned long len)
{
int ret = 0;