diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | Xr.h | 3 | ||||
-rw-r--r-- | src/Xr.h | 3 | ||||
-rw-r--r-- | src/xr.c | 3 | ||||
-rw-r--r-- | src/xrgstate.c | 23 | ||||
-rw-r--r-- | src/xrint.h | 9 | ||||
-rw-r--r-- | src/xrstate.c | 11 | ||||
-rw-r--r-- | src/xrsurface.c | 29 | ||||
-rw-r--r-- | xr.c | 3 | ||||
-rw-r--r-- | xrgstate.c | 23 | ||||
-rw-r--r-- | xrint.h | 9 | ||||
-rw-r--r-- | xrstate.c | 11 | ||||
-rw-r--r-- | xrsurface.c | 29 |
13 files changed, 113 insertions, 52 deletions
@@ -1,3 +1,12 @@ +2002-10-28 Carl Worth <cworth@east.isi.edu> + + * xrstate.c (_XrStatePop): Added error case for XrRestore without + matching XrSave. + + * xrsurface.c (_XrSurfaceInit, _XrSurfaceReference) + (_XrSurfaceDereference): Added reference counting to XrSurface to + patch a memory leak. + 2002-10-26 Carl Worth <cworth@isi.edu> * xrtransform.c (_XrTransformDistance): @@ -200,7 +200,8 @@ XrShowText(XrState *xrs, const char *utf8); typedef enum _XrStatus { XrStatusSuccess = 0, - XrStatusNoMemory + XrStatusNoMemory, + XrStatusInvalidRestore } XrStatus; XrStatus @@ -200,7 +200,8 @@ XrShowText(XrState *xrs, const char *utf8); typedef enum _XrStatus { XrStatusSuccess = 0, - XrStatusNoMemory + XrStatusNoMemory, + XrStatusInvalidRestore } XrStatus; XrStatus @@ -56,9 +56,6 @@ XrSave(XrState *xrs) void XrRestore(XrState *xrs) { - /* XXX: BUG: Calling XrRestore without a matching XrSave shoud - flag an error. Also, in order to prevent crashes, XrStatePop - should not be called in that case. */ if (xrs->status) return; diff --git a/src/xrgstate.c b/src/xrgstate.c index fd43f23d..fa455e27 100644 --- a/src/xrgstate.c +++ b/src/xrgstate.c @@ -65,8 +65,8 @@ _XrGStateInit(XrGState *gstate, Display *dpy) gstate->alphaFormat = XcFindStandardFormat(dpy, PictStandardA8); _XrSurfaceInit(&gstate->surface, dpy); - _XrSurfaceInit(&gstate->src, dpy); + _XrColorInit(&gstate->color); _XrSurfaceSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat); @@ -93,8 +93,8 @@ _XrGStateInitCopy(XrGState *gstate, XrGState *other) memcpy (gstate->dashes, other->dashes, other->ndashes * sizeof (double)); } - _XrSurfaceInit(&gstate->src, gstate->dpy); - _XrSurfaceSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat); + _XrSurfaceReference(&gstate->surface); + _XrSurfaceReference(&gstate->src); status = _XrPathInitCopy(&gstate->path, &other->path); if (status) @@ -118,9 +118,11 @@ _XrGStateInitCopy(XrGState *gstate, XrGState *other) void _XrGStateDeinit(XrGState *gstate) { + _XrSurfaceDereference(&gstate->src); + _XrSurfaceDereference(&gstate->surface); + _XrColorDeinit(&gstate->color); - _XrSurfaceDeinit(&gstate->src); - _XrSurfaceDeinit(&gstate->surface); + _XrTransformDeinit(&gstate->ctm); _XrTransformDeinit(&gstate->ctm_inverse); @@ -563,7 +565,16 @@ _XrGStateFill(XrGState *gstate) XrStatus _XrGStateShowText(XrGState *gstate, const char *utf8) { - /* XXX: NYI */ + /* + XftDrawStringUtf8(gstate->xft_draw, + gstate->xft_color, + gstate->font, + gstate->current_pt.x, + gstate->current_pt.y, + utf8, + strlen(utf8)); + */ + return XrStatusSuccess; } diff --git a/src/xrint.h b/src/xrint.h index ea37fe71..a2ff6fd5 100644 --- a/src/xrint.h +++ b/src/xrint.h @@ -175,7 +175,8 @@ typedef struct _XrSurface { XcFormat *xcformat; XcSurface *xcsurface; - XcSurface *alpha; + + unsigned int ref_count; } XrSurface; typedef struct _XrColor { @@ -455,6 +456,12 @@ void _XrSurfaceInit(XrSurface *surface, Display *dpy); void +_XrSurfaceReference(XrSurface *surface); + +void +_XrSurfaceDereference(XrSurface *surface); + +void _XrSurfaceDeinit(XrSurface *surface); void diff --git a/src/xrstate.c b/src/xrstate.c index 395bc97e..26b9f6e6 100644 --- a/src/xrstate.c +++ b/src/xrstate.c @@ -95,12 +95,13 @@ _XrStatePop(XrState *xrs) { XrGState *top; - if (xrs->stack) { - top = xrs->stack; - xrs->stack = top->next; + if (xrs->stack == NULL) + return XrStatusInvalidRestore; - _XrGStateDestroy(top); - } + top = xrs->stack; + xrs->stack = top->next; + + _XrGStateDestroy(top); return XrStatusSuccess; } diff --git a/src/xrsurface.c b/src/xrsurface.c index c746e8d7..ab170bf7 100644 --- a/src/xrsurface.c +++ b/src/xrsurface.c @@ -45,21 +45,30 @@ _XrSurfaceInit(XrSurface *surface, Display *dpy) surface->xcformat = 0; surface->xcsurface = 0; - surface->alpha = 0; + + surface->ref_count = 0; +} + +void +_XrSurfaceReference(XrSurface *surface) +{ + surface->ref_count++; +} + +void +_XrSurfaceDereference(XrSurface *surface) +{ + if (surface->ref_count == 0) + _XrSurfaceDeinit(surface); + else + surface->ref_count--; } void _XrSurfaceDeinit(XrSurface *surface) { - /* XXX: BUG: I'm not sure how to correctly deal with this. With the - semantics of XrSave, we can share the surface, but we do want - the last one freed eventually. Maybe I can reference count -- - or maybe I can free the surface when I finally push to the - bottom of the stack. - - if (surface->surface) { - XcFreeSurface(surface->dpy, surface->surface); - } */ + if (surface->xcsurface) + XcFreeSurface(surface->dpy, surface->xcsurface); } void @@ -56,9 +56,6 @@ XrSave(XrState *xrs) void XrRestore(XrState *xrs) { - /* XXX: BUG: Calling XrRestore without a matching XrSave shoud - flag an error. Also, in order to prevent crashes, XrStatePop - should not be called in that case. */ if (xrs->status) return; @@ -65,8 +65,8 @@ _XrGStateInit(XrGState *gstate, Display *dpy) gstate->alphaFormat = XcFindStandardFormat(dpy, PictStandardA8); _XrSurfaceInit(&gstate->surface, dpy); - _XrSurfaceInit(&gstate->src, dpy); + _XrColorInit(&gstate->color); _XrSurfaceSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat); @@ -93,8 +93,8 @@ _XrGStateInitCopy(XrGState *gstate, XrGState *other) memcpy (gstate->dashes, other->dashes, other->ndashes * sizeof (double)); } - _XrSurfaceInit(&gstate->src, gstate->dpy); - _XrSurfaceSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat); + _XrSurfaceReference(&gstate->surface); + _XrSurfaceReference(&gstate->src); status = _XrPathInitCopy(&gstate->path, &other->path); if (status) @@ -118,9 +118,11 @@ _XrGStateInitCopy(XrGState *gstate, XrGState *other) void _XrGStateDeinit(XrGState *gstate) { + _XrSurfaceDereference(&gstate->src); + _XrSurfaceDereference(&gstate->surface); + _XrColorDeinit(&gstate->color); - _XrSurfaceDeinit(&gstate->src); - _XrSurfaceDeinit(&gstate->surface); + _XrTransformDeinit(&gstate->ctm); _XrTransformDeinit(&gstate->ctm_inverse); @@ -563,7 +565,16 @@ _XrGStateFill(XrGState *gstate) XrStatus _XrGStateShowText(XrGState *gstate, const char *utf8) { - /* XXX: NYI */ + /* + XftDrawStringUtf8(gstate->xft_draw, + gstate->xft_color, + gstate->font, + gstate->current_pt.x, + gstate->current_pt.y, + utf8, + strlen(utf8)); + */ + return XrStatusSuccess; } @@ -175,7 +175,8 @@ typedef struct _XrSurface { XcFormat *xcformat; XcSurface *xcsurface; - XcSurface *alpha; + + unsigned int ref_count; } XrSurface; typedef struct _XrColor { @@ -455,6 +456,12 @@ void _XrSurfaceInit(XrSurface *surface, Display *dpy); void +_XrSurfaceReference(XrSurface *surface); + +void +_XrSurfaceDereference(XrSurface *surface); + +void _XrSurfaceDeinit(XrSurface *surface); void @@ -95,12 +95,13 @@ _XrStatePop(XrState *xrs) { XrGState *top; - if (xrs->stack) { - top = xrs->stack; - xrs->stack = top->next; + if (xrs->stack == NULL) + return XrStatusInvalidRestore; - _XrGStateDestroy(top); - } + top = xrs->stack; + xrs->stack = top->next; + + _XrGStateDestroy(top); return XrStatusSuccess; } diff --git a/xrsurface.c b/xrsurface.c index c746e8d7..ab170bf7 100644 --- a/xrsurface.c +++ b/xrsurface.c @@ -45,21 +45,30 @@ _XrSurfaceInit(XrSurface *surface, Display *dpy) surface->xcformat = 0; surface->xcsurface = 0; - surface->alpha = 0; + + surface->ref_count = 0; +} + +void +_XrSurfaceReference(XrSurface *surface) +{ + surface->ref_count++; +} + +void +_XrSurfaceDereference(XrSurface *surface) +{ + if (surface->ref_count == 0) + _XrSurfaceDeinit(surface); + else + surface->ref_count--; } void _XrSurfaceDeinit(XrSurface *surface) { - /* XXX: BUG: I'm not sure how to correctly deal with this. With the - semantics of XrSave, we can share the surface, but we do want - the last one freed eventually. Maybe I can reference count -- - or maybe I can free the surface when I finally push to the - bottom of the stack. - - if (surface->surface) { - XcFreeSurface(surface->dpy, surface->surface); - } */ + if (surface->xcsurface) + XcFreeSurface(surface->dpy, surface->xcsurface); } void |