mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Amit Choudhary" <amit2030@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: potential mem leak when system is low on memory
Date: Mon, 16 Oct 2006 15:52:00 -0700	[thread overview]
Message-ID: <123917630610161552o3d71416yf3df76c49c3e7c22@mail.gmail.com> (raw)

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

             reply	other threads:[~2006-10-16 22:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-16 22:52 Amit Choudhary [this message]
2006-10-17  8:10 ` Jarek Poplawski
2006-10-17 18:58   ` Amit Choudhary

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=123917630610161552o3d71416yf3df76c49c3e7c22@mail.gmail.com \
    --to=amit2030@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®