[PATCH RESEND] DRI2: Fix memory leak when a screen is not DRI2 capable.

Kusanagi Kouichi slash at ac.auone-net.jp
Wed Dec 14 20:41:25 PST 2011


On 2011-12-14 19:35:37 +0100, Julien Cristau wrote:
> On Wed, Dec 14, 2011 at 20:43:11 +0900, Kusanagi Kouichi wrote:
> 
> > Signed-off-by: Kusanagi Kouichi <slash at ac.auone-net.jp>
> > Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
> > ---
> >  glx/glxdri2.c |   13 +++++++------
> >  1 files changed, 7 insertions(+), 6 deletions(-)
> > 
> > diff --git a/glx/glxdri2.c b/glx/glxdri2.c
> > index 8187a3e..b2174f5 100644
> > --- a/glx/glxdri2.c
> > +++ b/glx/glxdri2.c
> > @@ -693,28 +693,29 @@ initializeExtensions(__GLXDRIscreen *screen)
> >  static __GLXscreen *
> >  __glXDRIscreenProbe(ScreenPtr pScreen)
> >  {
> > +    int fd;
> >      const char *driverName, *deviceName;
> >      __GLXDRIscreen *screen;
> >      size_t buffer_size;
> >      ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
> >  
> > -    screen = calloc(1, sizeof *screen);
> > -    if (screen == NULL)
> > -	return NULL;
> > -
> >      if (!xf86LoaderCheckSymbol("DRI2Connect") ||
> > -	!DRI2Connect(pScreen, DRI2DriverDRI,
> > -		     &screen->fd, &driverName, &deviceName)) {
> > +	!DRI2Connect(pScreen, DRI2DriverDRI, &fd, &driverName, &deviceName)) {
> >  	LogMessage(X_INFO,
> >  		   "AIGLX: Screen %d is not DRI2 capable\n", pScreen->myNum);
> >  	return NULL;
> >      }
> >  
> > +    screen = calloc(1, sizeof *screen);
> > +    if (screen == NULL)
> > +	return NULL;
> > +
> 
> seems like you're trading a memory leak for a fd leak?

IIUC, a returned fd is being managed by a driver.


More information about the xorg-devel mailing list