From: "Robert P. J. Day" <rpjday@crashcourse.ca>
To: Philippe De Muyter <phdm@macqel.be>
Cc: gregkh@suse.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH kobjects] Fix a rare memory leak in kobject_set_name_vargs
Date: Sat, 13 Mar 2010 07:53:59 -0500 (EST) [thread overview]
Message-ID: <alpine.LFD.2.00.1003130752001.8523@localhost> (raw)
In-Reply-To: <20100313124324.GA15244@frolo.macqel>
On Sat, 13 Mar 2010, Philippe De Muyter wrote:
> Hello Greg,
>
> This is a possible memory leak that I discovered only by accidental code
> reading.
>
> --
>
> If kvasprintf fails in kobject_set_name_vargs, the memory used by
> the original kobj->name is leaked. Fix that. I also avoid useless
> memory accesses to kobj->name by using the local variables old_name
> and new_name instead.
>
> Signed-off-by: Philippe De Muyter <phdm@macqel.be>
>
> diff -r 373fdd3df333 linux-2.6.x/lib/kobject.c
> --- a/linux-2.6.x/lib/kobject.c Wed Aug 19 23:26:44 2009 +0200
> +++ b/linux-2.6.x/lib/kobject.c Sat Mar 13 13:35:43 2010 +0100
> @@ -216,20 +216,22 @@ int kobject_set_name_vargs(struct kobjec
> va_list vargs)
> {
> const char *old_name = kobj->name;
> + char *new_name;
> char *s;
>
> - if (kobj->name && !fmt)
> + if (old_name && !fmt)
> return 0;
>
> - kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
> - if (!kobj->name)
> + new_name = kvasprintf(GFP_KERNEL, fmt, vargs);
> + if (!new_name)
> return -ENOMEM;
>
> /* ewww... some of these buggers have '/' in the name ... */
> - while ((s = strchr(kobj->name, '/')))
> + while ((s = strchr(new_name, '/')))
> s[0] = '!';
>
> kfree(old_name);
> + kobj->name = new_name;
> return 0;
> }
the routine kobject_set_name_vargs() is described in
Documentation/kobject.txt as "legacy cruft" to be removed at some
point, so it's not clear there's any value in "fixing" it.
rday
--
========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA
Linux Consulting, Training and Kernel Pedantry.
Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================
next prev parent reply other threads:[~2010-03-13 12:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-13 12:43 [PATCH kobjects] Fix a rare memory leak in kobject_set_name_vargs Philippe De Muyter
2010-03-13 12:53 ` Robert P. J. Day [this message]
2010-03-13 15:15 ` Eric Dumazet
2010-03-13 15:27 ` Robert P. J. Day
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=alpine.LFD.2.00.1003130752001.8523@localhost \
--to=rpjday@crashcourse.ca \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=phdm@macqel.be \
/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