glx: Fix drawable private leak on destroy
When a drawable goes away, we don't destroy the GLX drawable in full, since it may be current for a context. This means that when the drawable is destroyed in full later, the backend doesn't get a chance to destroy resources associated with the drawable (the DRI2Drawable). With this patch, we destroy the GLX drawable in full when it goes away and then track down all contexts that reference it and NULL their pointers.
This commit is contained in:
parent
140463a197
commit
7b6400a1b8
|
@ -80,7 +80,6 @@ libglx_la_SOURCES = \
|
|||
glxscreens.c \
|
||||
glxscreens.h \
|
||||
glxserver.h \
|
||||
glxutil.c \
|
||||
glxutil.h \
|
||||
render2.c \
|
||||
render2swap.c \
|
||||
|
|
|
@ -193,18 +193,9 @@ validGlxDrawable(ClientPtr client, XID id, int type, int access_mode,
|
|||
void
|
||||
__glXContextDestroy(__GLXcontext *context)
|
||||
{
|
||||
if (!context->isDirect) {
|
||||
if (context->drawPriv)
|
||||
__glXUnrefDrawable(context->drawPriv);
|
||||
if (context->readPriv)
|
||||
__glXUnrefDrawable(context->readPriv);
|
||||
context->drawPriv = NULL;
|
||||
context->readPriv = NULL;
|
||||
}
|
||||
__glXFlushContextCache();
|
||||
}
|
||||
|
||||
|
||||
static void __glXdirectContextDestroy(__GLXcontext *context)
|
||||
{
|
||||
__glXContextDestroy(context);
|
||||
|
@ -320,6 +311,8 @@ DoCreateContext(__GLXclientState *cl, GLXContextID gcId,
|
|||
glxc->isDirect = isDirect;
|
||||
glxc->renderMode = GL_RENDER;
|
||||
|
||||
__glXAddToContextList(glxc);
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
|
@ -639,10 +632,6 @@ DoMakeCurrent(__GLXclientState *cl,
|
|||
}
|
||||
__glXFlushContextCache();
|
||||
if (!prevglxc->isDirect) {
|
||||
if (prevglxc->drawPriv)
|
||||
__glXUnrefDrawable(prevglxc->drawPriv);
|
||||
if (prevglxc->readPriv)
|
||||
__glXUnrefDrawable(prevglxc->readPriv);
|
||||
prevglxc->drawPriv = NULL;
|
||||
prevglxc->readPriv = NULL;
|
||||
}
|
||||
|
@ -662,8 +651,6 @@ DoMakeCurrent(__GLXclientState *cl,
|
|||
}
|
||||
|
||||
glxc->isCurrent = GL_TRUE;
|
||||
__glXRefDrawable(glxc->drawPriv);
|
||||
__glXRefDrawable(glxc->readPriv);
|
||||
}
|
||||
|
||||
if (prevglxc) {
|
||||
|
@ -1090,6 +1077,33 @@ int __glXDisp_GetFBConfigsSGIX(__GLXclientState *cl, GLbyte *pc)
|
|||
return DoGetFBConfigs(cl, req->screen);
|
||||
}
|
||||
|
||||
GLboolean
|
||||
__glXDrawableInit(__GLXdrawable *drawable,
|
||||
__GLXscreen *screen, DrawablePtr pDraw, int type,
|
||||
XID drawId, __GLXconfig *config)
|
||||
{
|
||||
drawable->pDraw = pDraw;
|
||||
drawable->type = type;
|
||||
drawable->drawId = drawId;
|
||||
drawable->config = config;
|
||||
drawable->eventMask = 0;
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
__glXDrawableRelease(__GLXdrawable *drawable)
|
||||
{
|
||||
ScreenPtr pScreen = drawable->pDraw->pScreen;
|
||||
|
||||
switch (drawable->type) {
|
||||
case GLX_DRAWABLE_PIXMAP:
|
||||
case GLX_DRAWABLE_PBUFFER:
|
||||
(*pScreen->DestroyPixmap)((PixmapPtr) drawable->pDraw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
DoCreateGLXDrawable(ClientPtr client, __GLXscreen *pGlxScreen, __GLXconfig *config,
|
||||
DrawablePtr pDraw, XID glxDrawableId, int type)
|
||||
|
|
|
@ -67,11 +67,6 @@ struct __GLXdrawable {
|
|||
*/
|
||||
__GLXconfig *config;
|
||||
|
||||
/*
|
||||
** reference count
|
||||
*/
|
||||
int refCount;
|
||||
|
||||
GLenum target;
|
||||
GLenum format;
|
||||
|
||||
|
|
|
@ -238,6 +238,8 @@ __glXDRIdrawableDestroy(__GLXdrawable *drawable)
|
|||
__glXleaveServer(GL_FALSE);
|
||||
}
|
||||
|
||||
__glXDrawableRelease(drawable);
|
||||
|
||||
xfree(private);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,6 +109,8 @@ __glXDRIdrawableDestroy(__GLXdrawable *drawable)
|
|||
if (drawable->pDraw != NULL)
|
||||
DRI2DestroyDrawable(drawable->pDraw);
|
||||
|
||||
__glXDrawableRelease(drawable);
|
||||
|
||||
xfree(private);
|
||||
}
|
||||
|
||||
|
|
|
@ -102,6 +102,8 @@ __glXDRIdrawableDestroy(__GLXdrawable *drawable)
|
|||
FreeScratchGC(private->gc);
|
||||
FreeScratchGC(private->swapgc);
|
||||
|
||||
__glXDrawableRelease(drawable);
|
||||
|
||||
xfree(private);
|
||||
}
|
||||
|
||||
|
|
42
glx/glxext.c
42
glx/glxext.c
|
@ -50,6 +50,7 @@
|
|||
** from the server's perspective.
|
||||
*/
|
||||
__GLXcontext *__glXLastContext;
|
||||
__GLXcontext *__glXContextList;
|
||||
|
||||
/*
|
||||
** X resources.
|
||||
|
@ -111,31 +112,46 @@ static int ContextGone(__GLXcontext* cx, XID id)
|
|||
return True;
|
||||
}
|
||||
|
||||
static __GLXcontext *glxPendingDestroyContexts;
|
||||
static __GLXcontext *glxAllContexts;
|
||||
static int glxServerLeaveCount;
|
||||
static int glxBlockClients;
|
||||
|
||||
/*
|
||||
** Destroy routine that gets called when a drawable is freed. A drawable
|
||||
** contains the ancillary buffers needed for rendering.
|
||||
*/
|
||||
static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
|
||||
{
|
||||
ScreenPtr pScreen = glxPriv->pDraw->pScreen;
|
||||
__GLXcontext *c;
|
||||
|
||||
switch (glxPriv->type) {
|
||||
case GLX_DRAWABLE_PIXMAP:
|
||||
case GLX_DRAWABLE_PBUFFER:
|
||||
(*pScreen->DestroyPixmap)((PixmapPtr) glxPriv->pDraw);
|
||||
break;
|
||||
for (c = glxAllContexts; c; c = c->next) {
|
||||
if (c->drawPriv == glxPriv)
|
||||
c->drawPriv = NULL;
|
||||
if (c->readPriv == glxPriv)
|
||||
c->readPriv = NULL;
|
||||
}
|
||||
|
||||
glxPriv->pDraw = NULL;
|
||||
glxPriv->drawId = 0;
|
||||
__glXUnrefDrawable(glxPriv);
|
||||
glxPriv->destroy(glxPriv);
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
static __GLXcontext *glxPendingDestroyContexts;
|
||||
static int glxServerLeaveCount;
|
||||
static int glxBlockClients;
|
||||
void __glXAddToContextList(__GLXcontext *cx)
|
||||
{
|
||||
cx->next = glxAllContexts;
|
||||
glxAllContexts = cx;
|
||||
}
|
||||
|
||||
void __glXRemoveFromContextList(__GLXcontext *cx)
|
||||
{
|
||||
__GLXcontext *c, **prev;
|
||||
|
||||
prev = &glxAllContexts;
|
||||
for (c = glxAllContexts; c; c = c->next)
|
||||
if (c == cx)
|
||||
*prev = c->next;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free a context.
|
||||
|
@ -150,6 +166,8 @@ GLboolean __glXFreeContext(__GLXcontext *cx)
|
|||
__glXFlushContextCache();
|
||||
}
|
||||
|
||||
__glXRemoveFromContextList(cx);
|
||||
|
||||
/* We can get here through both regular dispatching from
|
||||
* __glXDispatch() or as a callback from the resource manager. In
|
||||
* the latter case we need to lift the DRI lock manually. */
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
extern GLboolean __glXFreeContext(__GLXcontext *glxc);
|
||||
extern void __glXFlushContextCache(void);
|
||||
|
||||
extern void __glXAddToContextList(__GLXcontext *cx);
|
||||
extern void __glXErrorCallBack(GLenum code);
|
||||
extern void __glXClearErrorOccured(void);
|
||||
extern GLboolean __glXErrorOccured(void);
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
|
||||
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice including the dates of first publication and
|
||||
* either this permission notice or a reference to
|
||||
* http://oss.sgi.com/projects/FreeB/
|
||||
* shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Silicon Graphics, Inc.
|
||||
* shall not be used in advertising or otherwise to promote the sale, use or
|
||||
* other dealings in this Software without prior written authorization from
|
||||
* Silicon Graphics, Inc.
|
||||
*/
|
||||
|
||||
#define FONT_PCF
|
||||
#ifdef HAVE_DIX_CONFIG_H
|
||||
#include <dix-config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "glxserver.h"
|
||||
#include "glxutil.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Drawable private stuff */
|
||||
|
||||
void
|
||||
__glXRefDrawable(__GLXdrawable *glxPriv)
|
||||
{
|
||||
glxPriv->refCount++;
|
||||
}
|
||||
|
||||
void
|
||||
__glXUnrefDrawable(__GLXdrawable *glxPriv)
|
||||
{
|
||||
glxPriv->refCount--;
|
||||
if (glxPriv->refCount == 0) {
|
||||
/* remove the drawable from the drawable list */
|
||||
FreeResourceByType(glxPriv->drawId, __glXDrawableRes, FALSE);
|
||||
glxPriv->destroy(glxPriv);
|
||||
}
|
||||
}
|
||||
|
||||
GLboolean
|
||||
__glXDrawableInit(__GLXdrawable *drawable,
|
||||
__GLXscreen *screen, DrawablePtr pDraw, int type,
|
||||
XID drawId, __GLXconfig *config)
|
||||
{
|
||||
drawable->pDraw = pDraw;
|
||||
drawable->type = type;
|
||||
drawable->drawId = drawId;
|
||||
drawable->refCount = 1;
|
||||
drawable->config = config;
|
||||
drawable->eventMask = 0;
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
|
@ -35,18 +35,11 @@
|
|||
* Silicon Graphics, Inc.
|
||||
*/
|
||||
|
||||
/* relate contexts with drawables */
|
||||
extern void __glXAssociateContext(__GLXcontext *glxc);
|
||||
extern void __glXDeassociateContext(__GLXcontext *glxc);
|
||||
|
||||
/* drawable management */
|
||||
extern void __glXRefDrawable(__GLXdrawable *glxPriv);
|
||||
extern void __glXUnrefDrawable(__GLXdrawable *glxPriv);
|
||||
|
||||
extern GLboolean __glXDrawableInit(__GLXdrawable *drawable,
|
||||
__GLXscreen *screen,
|
||||
DrawablePtr pDraw, int type, XID drawID,
|
||||
__GLXconfig *config);
|
||||
extern void __glXDrawableRelease(__GLXdrawable *drawable);
|
||||
|
||||
/* context helper routines */
|
||||
extern __GLXcontext *__glXLookupContextByTag(__GLXclientState*, GLXContextTag);
|
||||
|
|
Loading…
Reference in New Issue
Block a user