diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2017-11-06 19:39:10 +0100 |
---|---|---|
committer | Stefan Berger <stefanb@linux.vnet.ibm.com> | 2017-12-14 23:39:14 -0500 |
commit | 8df4d8484f607d4973e66e93f2eba0b3f80c4238 (patch) | |
tree | f61c3ebad761b94a36d4c62186ef376c4c34f38f /hw/tpm | |
parent | 9f7c0ef2ffa02b3bf6bc630496b8df67c750edd3 (diff) |
tpm-passthrough: make it safer to destroy after creation
Check fds values before closing, to avoid close(-1).
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Diffstat (limited to 'hw/tpm')
-rw-r--r-- | hw/tpm/tpm_passthrough.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 7371d50739..aa9167e3c6 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -347,8 +347,12 @@ static void tpm_passthrough_inst_finalize(Object *obj) tpm_passthrough_cancel_cmd(TPM_BACKEND(obj)); - qemu_close(tpm_pt->tpm_fd); - qemu_close(tpm_pt->cancel_fd); + if (tpm_pt->tpm_fd >= 0) { + qemu_close(tpm_pt->tpm_fd); + } + if (tpm_pt->cancel_fd >= 0) { + qemu_close(tpm_pt->cancel_fd); + } qapi_free_TPMPassthroughOptions(tpm_pt->options); } |