crypto/scheduler: fix memory leak
authorPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 26 Apr 2018 15:09:50 +0000 (16:09 +0100)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 10 May 2018 16:46:19 +0000 (17:46 +0100)
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: stable@dpdk.org
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
drivers/crypto/scheduler/scheduler_multicore.c

index 15a57c3..644426e 100644 (file)
@@ -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 = {