If private context creation fails, the memory
allocated for it and for some of the rings created
was being leaked.
In case of failure, it must be freed.

Fixes: 4c07e0552f0a ("crypto/scheduler: add multicore scheduling mode")
Cc: sta...@dpdk.org

Signed-off-by: Pablo de Lara <pablo.de.lara.gua...@intel.com>
---
 drivers/crypto/scheduler/scheduler_multicore.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/scheduler/scheduler_multicore.c 
b/drivers/crypto/scheduler/scheduler_multicore.c
index 15a57c3db..644426e93 100644
--- a/drivers/crypto/scheduler/scheduler_multicore.c
+++ b/drivers/crypto/scheduler/scheduler_multicore.c
@@ -352,20 +352,29 @@ scheduler_create_private_ctx(struct rte_cryptodev *dev)
                                        rte_socket_id(), RING_F_SC_DEQ | 
RING_F_SP_ENQ);
                if (!mc_ctx->sched_enq_ring[i]) {
                        CS_LOG_ERR("Cannot create ring for worker %u", i);
-                       return -1;
+                       goto exit;
                }
                snprintf(r_name, sizeof(r_name), MC_SCHED_DEQ_RING_NAME_PREFIX 
"%u", i);
                mc_ctx->sched_deq_ring[i] = rte_ring_create(r_name, 
PER_SLAVE_BUFF_SIZE,
                                        rte_socket_id(), RING_F_SC_DEQ | 
RING_F_SP_ENQ);
                if (!mc_ctx->sched_deq_ring[i]) {
                        CS_LOG_ERR("Cannot create ring for worker %u", i);
-                       return -1;
+                       goto exit;
                }
        }
 
        sched_ctx->private_ctx = (void *)mc_ctx;
 
        return 0;
+
+exit:
+       for (i = 0; i < sched_ctx->nb_wc; i++) {
+               rte_ring_free(mc_ctx->sched_enq_ring[i]);
+               rte_ring_free(mc_ctx->sched_deq_ring[i]);
+       }
+       rte_free(mc_ctx);
+
+       return -1;
 }
 
 struct rte_cryptodev_scheduler_ops scheduler_mc_ops = {
-- 
2.14.3

Reply via email to