[PATCH v2] staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc()

xkernel.wang@foxmail.com posted 1 patch 4 years, 2 months ago
There is a newer version of this series
drivers/staging/r8188eu/os_dep/xmit_linux.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH v2] staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc()
Posted by xkernel.wang@foxmail.com 4 years, 2 months ago
From: Xiaoke Wang <xkernel.wang@foxmail.com>

In rtw_os_xmit_resource_alloc(), if `pxmitbuf->pxmit_urb[i]` is  
allocated in failure, the other resources allocated such as 
`pxmitbuf->pallocated_buf` allocated by kzalloc() and the other explored 
items allocated by usb_alloc_urb() will not be properly released.

To release the resources, this patch first re-explores the allocated 
items and uses usb_free_urb() to release them, then uses kree() to 
release `pxmitbuf->pallocated_buf`.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
ChangeLog:
v1->v2 update the description.
 drivers/staging/r8188eu/os_dep/xmit_linux.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/os_dep/xmit_linux.c b/drivers/staging/r8188eu/os_dep/xmit_linux.c
index 8c3f8f0..5a59f62 100644
--- a/drivers/staging/r8188eu/os_dep/xmit_linux.c
+++ b/drivers/staging/r8188eu/os_dep/xmit_linux.c
@@ -78,8 +78,12 @@ int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitb
 
 	for (i = 0; i < 8; i++) {
 		pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
-		if (!pxmitbuf->pxmit_urb[i])
+		if (!pxmitbuf->pxmit_urb[i]) {
+			while (i-- > 0)
+				usb_free_urb(pxmitbuf->pxmit_urb[i]);
+			kfree(pxmitbuf->pallocated_buf);
 			return _FAIL;
+		}
 	}
 	return _SUCCESS;
 }
--