diff mbox series

[2/2] cryptodev: fix memory-leak occurs on error path

Message ID 20221102090243.52140-3-helei.sig11@bytedance.com (mailing list archive)
State New, archived
Headers show
Series cryptodev: fix memory leak | expand

Commit Message

Lei He Nov. 2, 2022, 9:02 a.m. UTC
- 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 mbox series

Patch

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;