From: Jesper Juhl <jj@chaosbits.net>
To: linux-kernel@vger.kernel.org
Cc: Gerd Hoffmann <kraxel@suse.de>, Alan Cox <alan@linux.intel.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: tty, hvc, xen: leak? dead code? everything is fine?
Date: Thu, 12 Apr 2012 23:33:20 +0200 (CEST) [thread overview]
Message-ID: <alpine.LNX.2.00.1204122318480.7553@swampdragon.chaosbits.net> (raw)
Hi
Ok, so I'm staring at drivers/tty/hvc/hvc_xen.c::xen_hvm_console_init() -
to be specific, this code (and yes, it's late and I'm tired, so I may be
completely off, I admit that up front):
...
info = vtermno_to_xencons(HVC_COOKIE);
if (!info) {
info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL |
__GFP_ZERO);
if (!info)
return -ENOMEM;
}
/* already configured */
if (info->intfw != NULL)
return 0;
...
and either I'm completely overlooking something obvious or just being
stupid (which is certainly possible) or there is a problem here;
If 'info->intfw' is something else than NULL here, then it seems like
we'll leak the memory we allocated for 'info' when we return (in case
info started out as NULL and we just allocated it with kzalloc()).
So it seems like we should 'kfree(info)' before the 'return 0' statement,
but then again, we may not have entered the true branch of 'if (!info)'
and just allocated 'info' - would it still be right to free it in that
case?
Or *if* there's actually no way 'info->intfw' can actually be anything but
NULL in this case, then this would just be dead code (but that doesn't
seem to be the case).
At the very least, this looks fishy to me... Any feedback is welcome...
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.
next reply other threads:[~2012-04-12 21:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-12 21:33 Jesper Juhl [this message]
2012-04-12 22:00 ` Samuel Thibault
2012-04-13 11:05 ` Stefano Stabellini
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.LNX.2.00.1204122318480.7553@swampdragon.chaosbits.net \
--to=jj@chaosbits.net \
--cc=alan@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=konrad.wilk@oracle.com \
--cc=kraxel@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=stefano.stabellini@eu.citrix.com \
/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®