From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH libdrm] Fix memory leak with drmModeGetConnectorCurrent()
Date: Tue, 15 Dec 2015 16:17:41 +0200 [thread overview]
Message-ID: <20151215141741.GG4437@intel.com> (raw)
In-Reply-To: <20151215140545.GC24300@nuc-i3427.alporthouse.com>
On Tue, Dec 15, 2015 at 02:05:45PM +0000, Chris Wilson wrote:
> On Tue, Dec 15, 2015 at 03:59:28PM +0200, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > drmModeGetConnectorCurrent() must provide temporary storage for the
> > kernel to fill in at least one mode (asking for !=0 modes is how
> > you prevent the heavyweight probe in the kernel). Currently we malloc
> > that temp storage but we fail to free it before overwriting the
> > pointer with the address of the actual storage we use to store the
> > real mode list we get from the kernel in the second ioctl call.
> >
> > Let's just keep the temporary storage on the stack and thus we avoid the
> > leak and also eliminate some pointless mallocs.
> >
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Fixes: 5ed5fa10600f ("mode: Retrieve only the current information for a Connector")
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> > xf86drmMode.c | 11 +++++++----
> > 1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/xf86drmMode.c b/xf86drmMode.c
> > index ab6b5195e8d3..7710061865ee 100644
> > --- a/xf86drmMode.c
> > +++ b/xf86drmMode.c
> > @@ -475,12 +475,13 @@ _drmModeGetConnector(int fd, uint32_t connector_id, int probe)
> > {
> > struct drm_mode_get_connector conn, counts;
> > drmModeConnectorPtr r = NULL;
> > + struct drm_mode_modeinfo stack_mode;
> >
> > memclear(conn);
> > conn.connector_id = connector_id;
> > if (!probe) {
> > conn.count_modes = 1;
> > - conn.modes_ptr = VOID2U64(drmMalloc(sizeof(struct drm_mode_modeinfo)));
> > + conn.modes_ptr = VOID2U64(&stack_mode);
> > }
>
> If you just made this change, we wouldn't need the hunks below (and I
> wouln't have to look at so much shouting).
That was my initial plan, but then I figured we could also skip the
other malloc for disconnected connectors.
>
> Either way,
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> -Chris
>
> --
> Chris Wilson, Intel Open Source Technology Centre
--
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2015-12-15 14:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-15 13:59 [PATCH libdrm] Fix memory leak with drmModeGetConnectorCurrent() ville.syrjala
2015-12-15 14:05 ` Chris Wilson
2015-12-15 14:17 ` Ville Syrjälä [this message]
2016-01-07 17:39 ` Ville Syrjälä
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=20151215141741.GG4437@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=dri-devel@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.