[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_280D048C193D178A239D222D5C54C9EEFF05@qq.com>
Date: Tue, 3 May 2022 14:58:55 +0800
From: xkernel.wang@...mail.com
To: Larry.Finger@...inger.net, florian.c.schilhabel@...glemail.com,
gregkh@...uxfoundation.org
Cc: linux-staging@...ts.linux.dev, linux-kernel@...r.kernel.org,
Xiaoke Wang <xkernel.wang@...mail.com>
Subject: [PATCH 03/12] staging: rtl8712: fix potential memory leak in r8712_init_drv_sw()
From: Xiaoke Wang <xkernel.wang@...mail.com>
In r8712_init_drv_sw(), there are various error paths do not properly
release the previous allocated resources but directly return the error
status, which leads to various memory leaks.
To properly release the resources, this patch unifies the error handler
of r8712_init_drv_sw().
According to the allocation sequence, if the init function returns
failure, it will jump to the corresponding error tag.
Signed-off-by: Xiaoke Wang <xkernel.wang@...mail.com>
---
drivers/staging/rtl8712/os_intfs.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index 003e972..43a7953 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -304,10 +304,10 @@ int r8712_init_drv_sw(struct _adapter *padapter)
padapter->cmdpriv.padapter = padapter;
ret = r8712_init_evt_priv(&padapter->evtpriv);
if (ret)
- return ret;
+ goto free_cmd_priv;
ret = r8712_init_mlme_priv(padapter);
if (ret)
- return ret;
+ goto free_evt_priv;
_r8712_init_xmit_priv(&padapter->xmitpriv, padapter);
_r8712_init_recv_priv(&padapter->recvpriv, padapter);
memset((unsigned char *)&padapter->securitypriv, 0,
@@ -316,13 +316,25 @@ int r8712_init_drv_sw(struct _adapter *padapter)
r8712_use_tkipkey_handler, 0);
ret = _r8712_init_sta_priv(&padapter->stapriv);
if (ret)
- return ret;
+ goto free_recv_priv;
padapter->stapriv.padapter = padapter;
r8712_init_bcmc_stainfo(padapter);
r8712_init_pwrctrl_priv(padapter);
mp871xinit(padapter);
init_default_value(padapter);
r8712_InitSwLeds(padapter);
+ return 0;
+
+free_recv_priv:
+ _r8712_free_recv_priv(&padapter->recvpriv);
+free_xmit_priv:
+ _free_xmit_priv(&padapter->xmitpriv);
+free_mlme_priv:
+ r8712_free_mlme_priv(&padapter->mlmepriv);
+free_evt_priv:
+ r8712_free_evt_priv(&padapter->evtpriv);
+free_cmd_priv:
+ r8712_free_cmd_priv(&padapter->cmdpriv);
return ret;
}
--
Powered by blists - more mailing lists