[Mesa-dev] [PATCH 2/2] glx: clean-up __glXInitialize handling
Emil Velikov
emil.l.velikov at gmail.com
Sun Mar 16 07:10:17 PDT 2014
Consistently check for the function return status to prevent
null ptr deref, and stop calling it without a purpose.
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
src/glx/dri2_glx.c | 21 +++++++++++++++------
src/glx/dri3_glx.c | 8 ++++----
src/glx/drisw_glx.c | 5 +----
3 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 298e771..c84fda9 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -749,7 +749,8 @@ unsigned dri2GetSwapEventType(Display* dpy, XID drawable)
struct glx_display *glx_dpy = __glXInitialize(dpy);
__GLXDRIdrawable *pdraw;
pdraw = dri2GetGlxDrawableFromXDrawableId(dpy, drawable);
- if (!pdraw || !(pdraw->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
+
+ if (!glx_dpy || !pdraw || !(pdraw->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
return 0;
return glx_dpy->codes->first_event + GLX_BufferSwapComplete;
}
@@ -830,10 +831,14 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
struct glx_display *dpyPriv = __glXInitialize(priv->base.psc->dpy);
struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
- struct dri2_display *pdp =
- (struct dri2_display *)dpyPriv->dri2Display;
+ struct dri2_display *pdp;
int64_t ret = 0;
+ if (dpyPriv == NULL)
+ return;
+
+ pdp = (struct dri2_display *) dpyPriv->dri2Display;
+
/* Check we have the right attachments */
if (!priv->have_back)
return ret;
@@ -1048,11 +1053,10 @@ dri2_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
struct glx_context *gc = __glXGetCurrentContext();
struct dri2_context *pcp = (struct dri2_context *) gc;
__GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
- struct glx_display *dpyPriv = __glXInitialize(dpy);
struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
struct dri2_screen *psc;
- if (dpyPriv != NULL && pdraw != NULL) {
+ if (pdraw != NULL) {
psc = (struct dri2_screen *) base->psc;
if (psc->texBuffer->base.version >= 3 &&
@@ -1359,9 +1363,14 @@ _X_HIDDEN __GLXDRIdrawable *
dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id)
{
struct glx_display *d = __glXInitialize(dpy);
- struct dri2_display *pdp = (struct dri2_display *) d->dri2Display;
+ struct dri2_display *pdp;
__GLXDRIdrawable *pdraw;
+ if (d == NULL)
+ return NULL;
+
+ pdp = (struct dri2_display *) d->dri2Display;
+
if (__glxHashLookup(pdp->dri2Hash, id, (void *) &pdraw) == 0)
return pdraw;
diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index 4cde9ef..93c5567 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -302,9 +302,13 @@ dri3_create_drawable(struct glx_screen *base, XID xDrawable,
{
struct dri3_drawable *pdraw;
struct dri3_screen *psc = (struct dri3_screen *) base;
+ struct glx_display *dpyPriv = __glXInitialize(psc->base.dpy);
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
+ if (dpyPriv == NULL)
+ return NULL;
+
pdraw = calloc(1, sizeof(*pdraw));
if (!pdraw)
return NULL;
@@ -335,8 +339,6 @@ dri3_create_drawable(struct glx_screen *base, XID xDrawable,
dri3_update_num_back(pdraw);
- (void) __glXInitialize(psc->base.dpy);
-
/* Create a new drawable */
pdraw->driDrawable =
(*psc->image_driver->createNewDrawable) (psc->driScreen,
@@ -694,8 +696,6 @@ dri3_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate)
psc = (struct dri3_screen *) pdraw->base.psc;
- (void) __glXInitialize(psc->base.dpy);
-
gc = __glXGetCurrentContext();
dri3_flush(psc, pdraw, __DRI2_FLUSH_DRAWABLE, __DRI2_THROTTLE_FLUSHFRONT);
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index 751626b..8c96a9c 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -316,8 +316,6 @@ drisw_bind_tex_image(Display * dpy,
struct drisw_drawable *pdraw = (struct drisw_drawable *) base;
struct drisw_screen *psc;
- __glXInitialize(dpy);
-
if (pdraw != NULL) {
psc = (struct drisw_screen *) base->psc;
@@ -345,11 +343,10 @@ drisw_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
struct glx_context *gc = __glXGetCurrentContext();
struct drisw_context *pcp = (struct drisw_context *) gc;
__GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
- struct glx_display *dpyPriv = __glXInitialize(dpy);
struct drisw_drawable *pdraw = (struct drisw_drawable *) base;
struct drisw_screen *psc;
- if (dpyPriv != NULL && pdraw != NULL) {
+ if (pdraw != NULL) {
psc = (struct drisw_screen *) base->psc;
if (!psc->texBuffer)
--
1.9.0
More information about the mesa-dev
mailing list