brcm80211: Don't leak 'vbuffer' in brcmf_sdbrcm_write_vars()
authorJesper Juhl <jj@chaosbits.net>
Sun, 8 Jan 2012 22:41:21 +0000 (23:41 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Tue, 10 Jan 2012 20:46:40 +0000 (15:46 -0500)
If the memory allocation 'nvram_ularray = kmalloc(varsize,
GFP_ATOMIC);' fails we'll leak the memory allocated to 'vbuffer' when
we return -ENOMEM from the function.

This patch resolves the leak by kfree()'ing the allocated memory
before the return.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c

index 5a002a21f108aa23895ee59139c8fcb6ac37e643..f7eeee1dcdb66a8b3a09c5534bb8f15a15f09e91 100644 (file)
@@ -3119,8 +3119,10 @@ static int brcmf_sdbrcm_write_vars(struct brcmf_sdio *bus)
                /* Verify NVRAM bytes */
                brcmf_dbg(INFO, "Compare NVRAM dl & ul; varsize=%d\n", varsize);
                nvram_ularray = kmalloc(varsize, GFP_ATOMIC);
-               if (!nvram_ularray)
+               if (!nvram_ularray) {
+                       kfree(vbuffer);
                        return -ENOMEM;
+               }
 
                /* Upload image to verify downloaded contents. */
                memset(nvram_ularray, 0xaa, varsize);