staging: rtl8192e: rtllib_module: Fix memory leak in alloc_rtllib
PATCH 1/1 staging: rtl8192e: rtllib_module: Fix memory leak in alloc_rtllib
In the implementation of alloc_rtllib() the allocated dev is leaked in case of ieee->pHTInfo allocation failure. Release via free_netdev(dev).
--- drivers/staging/rtl8192e/rtllib_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_module.c +1 -1
@@ -125,7 +125,7 @@ struct net_device *alloc_rtllib(int sizeof_priv) ieee->pHTInfo =kzalloc (sizeof (struct rt_hi_throughput ),GFP_KERNEL );if (!ieee->pHTInfo) -return NULL ; + goto failed;HTUpdateDefaultSetting (ieee);HTInitializeHTInfo (ieee);
Signature · 1 line
2.17.1
Quoted 4 lines · Navid Emamdoost
In the implementation of
alloc_rtllib()the allocated dev is leaked in case ofieee->pHTInfoallocation failure. Release viafree_netdev(dev).Fixes 6869a11bff1d ("Staging: rtl8192e: Use !x instead of x == NULL")
This is not the commit that introduced this issue.
Quoted 10 lines
Signed-off-by Navid Emamdoost <[email protected]>--- drivers/staging/rtl8192e/rtllib_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/rtl8192e/rtllib_module.c +0
-0
drivers/staging/rtl8192e/rtllib_module.c struct net_device *alloc_rtllib(int sizeof_priv) · line 128
Quoted 5 lines
drivers/staging/rtl8192e/rtllib_module.c +1
-1@@ -125,7 +125,7 @@ struct net_device *alloc_rtllib(int sizeof_priv) ieee->pHTInfo =kzalloc (sizeof (struct rt_hi_throughput ),GFP_KERNEL );if (!ieee->pHTInfo) -return NULL ; + goto failed;
And you're still leaking ieee->networks and possibly a bunch of other allocations here. You need to call at least rtllib_networks_free() in the error path.
drivers/staging/rtl8192e/rtllib_module.c struct net_device *alloc_rtllib(int sizeof_priv) · line 131
Quoted 3 lines
drivers/staging/rtl8192e/rtllib_module.c +0
-0HTUpdateDefaultSetting (ieee);HTInitializeHTInfo (ieee);
Johan
Hi Johan,
Quoted 8 lines · Johan Hovold
Quoted 4 lines · Navid Emamdoost
In the implementation of
alloc_rtllib()the allocated dev is leaked in case ofieee->pHTInfoallocation failure. Release viafree_netdev(dev).Fixes 6869a11bff1d ("Staging: rtl8192e: Use !x instead of x == NULL")This is not the commit that introduced this issue.
Oops! That should be 94a799425eee8
Quoted 12 lines
Quoted 12 lines
Signed-off-by Navid Emamdoost <[email protected]>--- drivers/staging/rtl8192e/rtllib_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/rtl8192e/rtllib_module.c +0
-0@@ -125,7 +125,7 @@ struct net_device *alloc_rtllib(int sizeof_priv)
Quoted 8 lines
drivers/staging/rtl8192e/rtllib_module.c struct net_device *alloc_rtllib(int sizeof_priv) · line 128
Quoted 4 lines
drivers/staging/rtl8192e/rtllib_module.c +1
-1ieee->pHTInfo =kzalloc (sizeof (struct rt_hi_throughput ),GFP_KERNEL );if (!ieee->pHTInfo) -return NULL ; + goto failed;And you're still leaking
ieee->networksand possibly a bunch of other allocations here. You need to call at leastrtllib_networks_free()in the error path.
I'm not familiar with this code, but based on your hint I believe there should be something like free_rtllib() here, right? More specifically, rtllib_softmac_free() and lib80211_crypt_info_free() are needed along with rtllib_networks_free(). If you confirm that it works I can go ahead to prepare patch v2 with these releases.
Quoted 6 lines
drivers/staging/rtl8192e/rtllib_module.c struct net_device *alloc_rtllib(int sizeof_priv) · line 131
Quoted 4 lines
drivers/staging/rtl8192e/rtllib_module.c +0
-0HTUpdateDefaultSetting (ieee);HTInitializeHTInfo (ieee);Johan
Signature · 1 line
Navid.
Quoted 33 lines · Navid Emamdoost
Hi Johan,
Quoted 8 lines · Johan Hovold
Quoted 4 lines · Navid Emamdoost
In the implementation of
alloc_rtllib()the allocated dev is leaked in case ofieee->pHTInfoallocation failure. Release viafree_netdev(dev).Fixes 6869a11bff1d ("Staging: rtl8192e: Use !x instead of x == NULL")This is not the commit that introduced this issue.
Oops! That should be
94a799425eee8Quoted 12 lines
Quoted 12 lines
Signed-off-by Navid Emamdoost <[email protected]>--- drivers/staging/rtl8192e/rtllib_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/rtl8192e/rtllib_module.c +0
-0@@ -125,7 +125,7 @@ struct net_device *alloc_rtllib(int sizeof_priv)Quoted 8 lines
drivers/staging/rtl8192e/rtllib_module.c struct net_device *alloc_rtllib(int sizeof_priv) · line 128
Quoted 4 lines
drivers/staging/rtl8192e/rtllib_module.c +1
-1ieee->pHTInfo =kzalloc (sizeof (struct rt_hi_throughput ),GFP_KERNEL );if (!ieee->pHTInfo) -return NULL ; + goto failed;And you're still leaking
ieee->networksand possibly a bunch of other allocations here. You need to call at leastrtllib_networks_free()in the error path.
Quoted 2 lines
I'm not familiar with this code, but based on your hint I believe there should be something like
free_rtllib()here, right?
Right.
Quoted 4 lines
More specifically,
rtllib_softmac_free()andlib80211_crypt_info_free()are needed along withrtllib_networks_free(). If you confirm that it works I can go ahead to prepare patch v2 with these releases.
I can't confirm anything, that's your job. ;)
You need to trace the calls and allocations made in in alloc_rtllib() and make sure everything is released on errors. For a well-designed subsystem and driver this should end up looking a lot like the release function (free_rtllib()), but that's unfortunately not always the case.
Judging from a quick look at least rtllib_softmac_free() is also needed besides rtllib_networks_free(). And you probably want lib80211_crypt_info_free() as well for consistency even if the corresponding init functions doesn't seem to do any allocations currently.
Johan