From: Jarek Poplawski <jarkao2@o2.pl>
To: Amit Choudhary <amit2030@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: potential mem leak when system is low on memory
Date: Tue, 17 Oct 2006 10:10:20 +0200 [thread overview]
Message-ID: <20061017081020.GB1742@ff.dom.local> (raw)
In-Reply-To: <123917630610161552o3d71416yf3df76c49c3e7c22@mail.gmail.com>
On 17-10-2006 00:52, Amit Choudhary wrote:
> 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.
So you've found elementary programming bugs and it would
be nice to point this places.
Jarek P.
next prev parent reply other threads:[~2006-10-17 8:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-16 22:52 Amit Choudhary
2006-10-17 8:10 ` Jarek Poplawski [this message]
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=20061017081020.GB1742@ff.dom.local \
--to=jarkao2@o2.pl \
--cc=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®