mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* potential mem leak when system is low on memory
@ 2006-10-16 22:52 Amit Choudhary
  2006-10-17  8:10 ` Jarek Poplawski
  0 siblings, 1 reply; 3+ messages in thread
From: Amit Choudhary @ 2006-10-16 22:52 UTC (permalink / raw)
  To: linux-kernel

Hi All,

I was just scrubbing the kernel for checking the return ststus of
kmalloc(), and I saw at many places the following things. I just
wanted to report this.

1. If there are more than one kmalloc() calls in the same function,
and if kmalloc() returns NULL for one of them, then the memory
obtained from previous kmalloc() calls is not released.

Something like:

func()
{
    var1 = kmalloc(size);
    if (!var1)
         return -ENOMEM;

    var2 = kmalloc(size);
    if (!var2)
         return -ENOMEM;

/* mem  leak as var1 is not freed */

}

2. Sometimes, memory is allocated in a loop. So, if kmalloc() fails at
some point, memory allocated previously is not released.

func()
{
    for (i = 0; i < LENGTH; i++) {
            var1[i] = kmalloc(size);
            if (!var1[i])
                 return -ENOMEM;

/* mem leak as var1[0] to var1[i - 1] is not freed */

    }
}

So, already the system is running low on memory and on top of it there
are leaks.

-Amit

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

end of thread, other threads:[~2006-10-17 18:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-16 22:52 potential mem leak when system is low on memory Amit Choudhary
2006-10-17  8:10 ` Jarek Poplawski
2006-10-17 18:58   ` Amit Choudhary

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®