staging:rtl8192u: Possible memory leak?

John Whitmore arigead at gmail.com
Wed Sep 26 11:52:03 EDT 2018


I've been going through the rtl8192u driver in drivers/staging trying
to get a better understanding of the code. It's possibly not the
text book network driver but it seemed as good a place to start as
any.

So I'm looking at the allocation function in ieee80211_module.c:

struct net_device *alloc_ieee80211(int sizeof_priv)

And can't figure out how there's not a possible memory leak. Either
there is a memory leak or I'm misunderstanding the code. Possibly
the latter is more likely but I thought I'd ask for clarification.

The way I read the function the net_device is allocated with a call
to alloc_etherdev() and if that call fails the code does a
'goto failed'.

If the allocation of the net_device succeeds the funcion
ieee80211_networks_allocate() is called, which allocates an array
of 128 structures. If that allocation fails then again 'goto failed'

That's all fine so far but on line 160 a third allocation is attempted
and again 'goto failed' but ieee80211_network_free(ieee) is never
called to clean up from the call to ieee80211_networks_allocate()

This might all be a mute point as I seem to remember someone saying
that memory allocation never fails in Linux and this can only happen
if the first two allocations work and the third fails.

Still thought I'd ask and possibly learn why I'm wrong, on so many
levels ;)

jwhitmore



More information about the Kernelnewbies mailing list