Re: [PATCH v2 2/2] staging: r8188eu: fix potential memory leak in _rtw_init_xmit_priv()

From: Dan Carpenter
Date: Thu Mar 31 2022 - 07:24:03 EST


On Thu, Mar 31, 2022 at 06:58:16PM +0800, xkernel.wang@xxxxxxxxxxx wrote:
> +free_xmit_extbuf:
> + pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
> + while (i-- > 0) {
> + rtw_os_xmit_resource_free(padapter, pxmitbuf, (max_xmit_extbuf_size + XMITBUF_ALIGN_SZ));
> + pxmitbuf++;
> + }
> + vfree(pxmitpriv->pallocated_xmit_extbuf);
> + i = NR_XMITBUFF;
> +free_xmitbuf:
> + pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
> + while (i-- > 0) {
> + rtw_os_xmit_resource_free(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
> + pxmitbuf++;
> + }

This works... Presumably, it applies to staging-next even though it
doesn't apply to linux-next. So:

Reviewed-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

In an ideal world, pxmitpriv->pxmitbuf would be declared as an array of
struct instead of an array of u8. That would make it much simpler
because we could do

free_xmit_extbuf:
while (--i >= 0)
rtw_os_xmit_resource_free(pxmitpriv->pxmit_extbuf[i]);
vfree(pxmitpriv->pxmit_extbuf);
i = NR_XMITBUFF;
free_xmitbuf:
while (--i >= 0)
rtw_os_xmit_resource_free(pxmitpriv->pxmitbuf[i]);

regards,
dan carpenter