From 23b6502d88aed2e97179936a15c4cccbd8c61d84 Mon Sep 17 00:00:00 2001 From: chenguo Date: Thu, 26 Oct 2017 11:24:01 +0800 Subject: [PATCH] qcacmn: Fix memory leak for RX path of SDIO WLAN There is a memory leak for RX path of SDIO WLAN if skb allocation fails. Add condition check and free all resources for scenario. Change-Id: Ic4a58d3d4e93f1d6d57bfb045dfdeb131b24f72a CRs-Fixed: 2128051 --- hif/src/sdio/hif_sdio_recv.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/hif/src/sdio/hif_sdio_recv.c b/hif/src/sdio/hif_sdio_recv.c index fcd2da87d70c..548352ad177e 100644 --- a/hif/src/sdio/hif_sdio_recv.c +++ b/hif/src/sdio/hif_sdio_recv.c @@ -293,10 +293,18 @@ QDF_STATUS hif_dev_alloc_and_prepare_rx_packets(struct hif_sdio_device *pdev, /* for NO RESOURCE error, no need to flush data queue */ if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_RESOURCES)) { - while (!HTC_QUEUE_EMPTY(queue)) + while (!HTC_QUEUE_EMPTY(queue)) { + qdf_nbuf_t netbuf; packet = htc_packet_dequeue(queue); + if (packet == NULL) + break; + netbuf = (qdf_nbuf_t) packet->pNetBufContext; + if (netbuf) + qdf_nbuf_free(netbuf); + } } - + if (status == QDF_STATUS_E_RESOURCES) + status = QDF_STATUS_SUCCESS; return status; } @@ -967,8 +975,20 @@ QDF_STATUS hif_dev_recv_message_pending_handler(struct hif_sdio_device *pdev, hif_dev_recv_packet(pdev, packet, packet->ActualLength, mail_box_index); - if (QDF_IS_STATUS_ERROR(status)) + if (QDF_IS_STATUS_ERROR(status)) { + while (!HTC_QUEUE_EMPTY(&recv_pkt_queue)) { + qdf_nbuf_t netbuf; + packet = + htc_packet_dequeue(&recv_pkt_queue); + if (packet == NULL) + break; + netbuf = + (qdf_nbuf_t) packet->pNetBufContext; + if (netbuf) + qdf_nbuf_free(netbuf); + } break; + } /* sent synchronously, queue this packet for * synchronous completion */