[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] cryptodev: fix memory-leak occurs on error path
From: |
Lei He |
Subject: |
[PATCH 2/2] cryptodev: fix memory-leak occurs on error path |
Date: |
Wed, 2 Nov 2022 17:02:43 +0800 |
- Fix memory-leak when 'virtio_crypto_handle_request' returns non-zero
value.
- When error occurred, always pass negative status to function
'virtio_crypto_req_complete'.
Signed-off-by: Lei He <helei.sig11@bytedance.com>
---
hw/virtio/virtio-crypto.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 7ba63790d5..97da74e719 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -895,12 +895,15 @@ check_result:
if (ret == -EFAULT) {
return -1;
} else if (ret == -VIRTIO_CRYPTO_NOTSUPP) {
- virtio_crypto_req_complete(request, VIRTIO_CRYPTO_NOTSUPP);
+ virtio_crypto_req_complete(request, -VIRTIO_CRYPTO_NOTSUPP);
} else {
- cryptodev_backend_crypto_operation(vcrypto->cryptodev,
+ ret = cryptodev_backend_crypto_operation(vcrypto->cryptodev,
request, queue_index,
virtio_crypto_req_complete,
request);
+ if (ret < 0) {
+ virtio_crypto_req_complete(request, ret);
+ }
}
break;
@@ -911,7 +914,7 @@ check_result:
default:
error_report("virtio-crypto unsupported dataq opcode: %u",
opcode);
- virtio_crypto_req_complete(request, VIRTIO_CRYPTO_NOTSUPP);
+ virtio_crypto_req_complete(request, -VIRTIO_CRYPTO_NOTSUPP);
}
return 0;
--
2.11.0