All of lore.kernel.org
 help / color / mirror / Atom feed
* staging:rtl8192u: Possible memory leak?
@ 2018-09-26 15:52 John Whitmore
  2018-09-26 17:52 ` valdis.kletnieks at vt.edu
  0 siblings, 1 reply; 2+ messages in thread
From: John Whitmore @ 2018-09-26 15:52 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* staging:rtl8192u: Possible memory leak?
  2018-09-26 15:52 staging:rtl8192u: Possible memory leak? John Whitmore
@ 2018-09-26 17:52 ` valdis.kletnieks at vt.edu
  0 siblings, 0 replies; 2+ messages in thread
From: valdis.kletnieks at vt.edu @ 2018-09-26 17:52 UTC (permalink / raw)
  To: kernelnewbies

On Wed, 26 Sep 2018 16:52:03 +0100, John Whitmore said:

> 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.

If memory allocation never fails, it would be a moot point, not a mute point.

However, memory allocation can indeed fail, and often does.

And you are correct, there is a memory leak.  While looking at that, I found
another minor issue. Patch submitted.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-26 17:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-26 15:52 staging:rtl8192u: Possible memory leak? John Whitmore
2018-09-26 17:52 ` valdis.kletnieks at vt.edu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.