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

Julien Cristau jcristau at debian.org
Wed Dec 14 10:35:37 PST 2011


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?

Cheers,
Julien

>      screen->base.destroy        = __glXDRIscreenDestroy;
>      screen->base.createContext  = __glXDRIscreenCreateContext;
>      screen->base.createDrawable = __glXDRIscreenCreateDrawable;
>      screen->base.swapInterval   = __glXDRIdrawableSwapInterval;
>      screen->base.pScreen       = pScreen;
> +    screen->fd = fd;
>  
>      __glXInitExtensionEnableBits(screen->glx_enable_bits);
>  
> -- 
> 1.7.7.3
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list