[03/20] crypto/dpaa2_sec: fix memory leaks in error handlings

Message ID tencent_301A1EB7D3F9082E1DAC6F9B111091899807@qq.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series fix memory leaks in error handling |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Weiguo Li Feb. 22, 2022, 6:18 p.m. UTC
  When function returned from error handling branches, the memories were
not freed which caused a memory leak.

Fixes: 8d1f3a5d751b ("crypto/dpaa2_sec: support crypto operation")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
 drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

David Marchand June 24, 2022, 8:46 p.m. UTC | #1
On Tue, Feb 22, 2022 at 7:19 PM Weiguo Li <liwg06@foxmail.com> wrote:
>
> When function returned from error handling branches, the memories were
> not freed which caused a memory leak.
>
> Fixes: 8d1f3a5d751b ("crypto/dpaa2_sec: support crypto operation")

This is backport material.
Please add Cc: stable@dpdk.org in new revision.

>
> Signed-off-by: Weiguo Li <liwg06@foxmail.com>
> ---
>  drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
> index e62d04852b..3f8d4d213f 100644
> --- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
> +++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
> @@ -2037,12 +2037,15 @@ dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
>                 RTE_CACHE_LINE_SIZE);
>         if (!qp->rx_vq.q_storage) {
>                 DPAA2_SEC_ERR("malloc failed for q_storage");
> +               rte_free(qp);
>                 return -ENOMEM;
>         }
>         memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
>
>         if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
>                 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
> +               rte_free(qp->rx_vq.q_storage);
> +               rte_free(qp);
>                 return -ENOMEM;
>         }


Please rebase this fix, there was a new allocation introduced in this
code and I suspect this should be fixed too.
Thanks.
  

Patch

diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
index e62d04852b..3f8d4d213f 100644
--- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
+++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
@@ -2037,12 +2037,15 @@  dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 		RTE_CACHE_LINE_SIZE);
 	if (!qp->rx_vq.q_storage) {
 		DPAA2_SEC_ERR("malloc failed for q_storage");
+		rte_free(qp);
 		return -ENOMEM;
 	}
 	memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
 
 	if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
 		DPAA2_SEC_ERR("Unable to allocate dequeue storage");
+		rte_free(qp->rx_vq.q_storage);
+		rte_free(qp);
 		return -ENOMEM;
 	}