summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--Xr.h3
-rw-r--r--src/Xr.h3
-rw-r--r--src/xr.c3
-rw-r--r--src/xrgstate.c23
-rw-r--r--src/xrint.h9
-rw-r--r--src/xrstate.c11
-rw-r--r--src/xrsurface.c29
-rw-r--r--xr.c3
-rw-r--r--xrgstate.c23
-rw-r--r--xrint.h9
-rw-r--r--xrstate.c11
-rw-r--r--xrsurface.c29
13 files changed, 113 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index ce29e098..7e55e75f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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):
diff --git a/Xr.h b/Xr.h
index e0782522..d64b1aaa 100644
--- a/Xr.h
+++ b/Xr.h
@@ -200,7 +200,8 @@ XrShowText(XrState *xrs, const char *utf8);
typedef enum _XrStatus {
XrStatusSuccess = 0,
- XrStatusNoMemory
+ XrStatusNoMemory,
+ XrStatusInvalidRestore
} XrStatus;
XrStatus
diff --git a/src/Xr.h b/src/Xr.h
index e0782522..d64b1aaa 100644
--- a/src/Xr.h
+++ b/src/Xr.h
@@ -200,7 +200,8 @@ XrShowText(XrState *xrs, const char *utf8);
typedef enum _XrStatus {
XrStatusSuccess = 0,
- XrStatusNoMemory
+ XrStatusNoMemory,
+ XrStatusInvalidRestore
} XrStatus;
XrStatus
diff --git a/src/xr.c b/src/xr.c
index 4d3e3780..0e5787fc 100644
--- a/src/xr.c
+++ b/src/xr.c
@@ -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
diff --git a/xr.c b/xr.c
index 4d3e3780..0e5787fc 100644
--- a/xr.c
+++ b/xr.c
@@ -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/xrgstate.c b/xrgstate.c
index fd43f23d..fa455e27 100644
--- a/xrgstate.c
+++ b/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/xrint.h b/xrint.h
index ea37fe71..a2ff6fd5 100644
--- a/xrint.h
+++ b/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/xrstate.c b/xrstate.c
index 395bc97e..26b9f6e6 100644
--- a/xrstate.c
+++ b/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/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