cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH] fs, dlm: Don't leak, don't do pointless NULL checks and use kzalloc
       [not found] <alpine.LNX.2.00.1106292304380.3747@swampdragon.chaosbits.net>
@ 2011-06-29 21:40 ` David Teigland
       [not found]   ` <alpine.LNX.2.00.1106292344110.3747@swampdragon.chaosbits.net>
  0 siblings, 1 reply; 2+ messages in thread
From: David Teigland @ 2011-06-29 21:40 UTC (permalink / raw)
  To: cluster-devel.redhat.com

On Wed, Jun 29, 2011 at 11:09:27PM +0200, Jesper Juhl wrote:
> In fs/dlm/lock.c in the dlm_scan_waiters() function there are 3 small
> issues:
> 
> 1) first time through the loop we allocate memory for 'warned', if we
> then (in the loop) don't take the "if (!warned)" path and loop again,
> the second time through the loop we'll allocate memory again and store
> it to 'warned' without freeing the previous allocation - this leaks
> memory.

I don't think so; num_nodes won't be set to zero.

> 2) There's no need to test the return value of the allocation and do a
> memset if is succeedes. Just use kzalloc() to obtain zeroed memory.

fine

> 3) Since kfree() handles NULL pointers gracefully, the test of
> 'warned' against NULL before the kfree() after the loop is completely
> pointless. Remove it.

fine

ack if you want to push those two out yourself.
Dave



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

* [Cluster-devel] [PATCH] fs, dlm: Don't leak, don't do pointless NULL checks and use kzalloc
       [not found]   ` <alpine.LNX.2.00.1106292344110.3747@swampdragon.chaosbits.net>
@ 2011-06-29 22:17     ` David Teigland
  0 siblings, 0 replies; 2+ messages in thread
From: David Teigland @ 2011-06-29 22:17 UTC (permalink / raw)
  To: cluster-devel.redhat.com

On Wed, Jun 29, 2011 at 11:51:00PM +0200, Jesper Juhl wrote:
> > I don't think so; num_nodes won't be set to zero.
> 
> Hmm. How so?  Maybe I'm missing something obvious, but;
> num_nodes is initialized to zero at the beginning of the function, which 
> means that we'll definately do the first allocation in the loop.

Zero is meant to mean "first time through the loop".

> We then set num_nodes equal to ls->ls_num_nodes - what guarantees that 
> this will not be zero so we won't do a second allocation (and leak) the 
> second time through the loop?

That's just the nature of a lockspace, I guess -- it doesn't make sense or
exist without nodes in it.  I doubt any of the dlm code would work if that
weren't true.

Dave



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

end of thread, other threads:[~2011-06-29 22:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <alpine.LNX.2.00.1106292304380.3747@swampdragon.chaosbits.net>
2011-06-29 21:40 ` [Cluster-devel] [PATCH] fs, dlm: Don't leak, don't do pointless NULL checks and use kzalloc David Teigland
     [not found]   ` <alpine.LNX.2.00.1106292344110.3747@swampdragon.chaosbits.net>
2011-06-29 22:17     ` David Teigland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).