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>
This commit is contained in:
Marc-André Lureau 2017-11-06 19:39:10 +01:00 committed by Stefan Berger
parent 9f7c0ef2ff
commit 8df4d8484f
1 changed files with 6 additions and 2 deletions

View File

@ -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);
}