Commit bf109933 authored by Reiji Watanabe's avatar Reiji Watanabe Committed by Sean Christopherson

KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd

kvm_vm_elf_load() and elfhdr_get() open one file each, but they
never close the opened file descriptor.  If a test repeatedly
creates and destroys a VM with __vm_create(), which
(directly or indirectly) calls those two functions, the test
might end up getting a open failure with EMFILE.
Fix those two functions to close the file descriptor.
Signed-off-by: default avatarReiji Watanabe <reijiw@google.com>
Reviewed-by: default avatarOliver Upton <oliver.upton@linux.dev>
Reviewed-by: default avatarAndrew Jones <andrew.jones@linux.dev>
Reviewed-by: default avatarSean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/r/20221220170921.2499209-2-reijiw@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 7cb79f43
...@@ -90,6 +90,7 @@ static void elfhdr_get(const char *filename, Elf64_Ehdr *hdrp) ...@@ -90,6 +90,7 @@ static void elfhdr_get(const char *filename, Elf64_Ehdr *hdrp)
" hdrp->e_shentsize: %x\n" " hdrp->e_shentsize: %x\n"
" expected: %zx", " expected: %zx",
hdrp->e_shentsize, sizeof(Elf64_Shdr)); hdrp->e_shentsize, sizeof(Elf64_Shdr));
close(fd);
} }
/* VM ELF Load /* VM ELF Load
...@@ -190,4 +191,5 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename) ...@@ -190,4 +191,5 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename)
phdr.p_filesz); phdr.p_filesz);
} }
} }
close(fd);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment