[PATCH 5/9] Delete callbacks when extension are closed

Peter Hutterer peter.hutterer at who-t.net
Mon Feb 27 16:41:02 PST 2012


Fixes leaks such as

==20085==
==20085== 32 bytes in 1 blocks are still reachable in loss record 21 of 103
==20085==    at 0x4C2A4CD: malloc (vg_replace_malloc.c:236)
==20085==    by 0x439CF0: _AddCallback (dixutils.c:694)
==20085==    by 0x43A1F5: AddCallback (dixutils.c:872)
==20085==    by 0x5344FA: RenderExtensionInit (render.c:252)
==20085==    by 0x41C952: InitExtensions (miinitext.c:451)
==20085==    by 0x5AC918: main (main.c:208)

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 Xi/extinit.c        |    2 ++
 composite/compext.c |    8 +++++++-
 glx/glxext.c        |   17 +++++++++--------
 randr/randr.c       |    7 ++++++-
 render/render.c     |    8 +++++++-
 5 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/Xi/extinit.c b/Xi/extinit.c
index a81c8f1..bfc7905 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -1143,6 +1143,8 @@ IResetProc(ExtensionEntry * unused)
     EventSwapVector[DevicePresenceNotify] = NotImplemented;
     EventSwapVector[DevicePropertyNotify] = NotImplemented;
     RestoreExtensionEvents();
+
+    DeleteCallback(&ClientStateCallback, XIClientCallback, 0);
 }
 
 
diff --git a/composite/compext.c b/composite/compext.c
index 722587a..417571e 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -497,6 +497,12 @@ SProcCompositeDispatch (ClientPtr client)
 	return BadRequest;
 }
 
+static void
+CompositCloseDown(ExtensionEntry *entry)
+{
+    DeleteCallback (&ClientStateCallback, CompositeClientCallback, 0);
+}
+
 void
 CompositeExtensionInit (void)
 {
@@ -553,7 +559,7 @@ CompositeExtensionInit (void)
 
     extEntry = AddExtension (COMPOSITE_NAME, 0, 0,
 			     ProcCompositeDispatch, SProcCompositeDispatch,
-			     NULL, StandardMinorOpcode);
+			     CompositCloseDown, StandardMinorOpcode);
     if (!extEntry)
 	return;
     CompositeReqCode = (CARD8) extEntry->base;
diff --git a/glx/glxext.c b/glx/glxext.c
index 9cfc096..bb577c6 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -71,14 +71,6 @@ static DevPrivateKeyRec glxClientPrivateKeyRec;
 static int __glXDispatch(ClientPtr);
 
 /*
-** Called when the extension is reset.
-*/
-static void ResetExtension(ExtensionEntry* extEntry)
-{
-    __glXFlushContextCache();
-}
-
-/*
 ** Reset state used to keep track of large (multi-request) commands.
 */
 void __glXResetLargeCommandStatus(__GLXclientState *cl)
@@ -296,6 +288,15 @@ void GlxPushProvider(__GLXprovider *provider)
 }
 
 /*
+** Called when the extension is reset.
+*/
+static void ResetExtension(ExtensionEntry* extEntry)
+{
+    __glXFlushContextCache();
+    DeleteCallback(&ClientStateCallback, glxClientCallback, 0);
+}
+
+/*
 ** Initialize the GLX extension.
 */
 void GlxExtensionInit(void)
diff --git a/randr/randr.c b/randr/randr.c
index d337129..1bbb758 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -325,6 +325,11 @@ RRFreeEvents (pointer data, XID id)
     return 1;
 }
 
+static void RRCloseDown(ExtensionEntry *entry)
+{
+    DeleteCallback(&ClientStateCallback, RRClientCallback, 0);
+}
+
 void
 RRExtensionInit (void)
 {
@@ -347,7 +352,7 @@ RRExtensionInit (void)
 	return;
     extEntry = AddExtension (RANDR_NAME, RRNumberEvents, RRNumberErrors,
 			     ProcRRDispatch, SProcRRDispatch,
-			     NULL, StandardMinorOpcode);
+			     RRCloseDown, StandardMinorOpcode);
     if (!extEntry)
 	return;
     RRErrorBase = extEntry->errorBase;
diff --git a/render/render.c b/render/render.c
index d82e099..2709336 100644
--- a/render/render.c
+++ b/render/render.c
@@ -238,6 +238,12 @@ RenderClientCallback (CallbackListPtr	*list,
 RESTYPE	XRT_PICTURE;
 #endif
 
+static void
+RenderCloseDown(ExtensionEntry *entry)
+{
+    DeleteCallback(&ClientStateCallback, RenderClientCallback, 0);
+}
+
 void
 RenderExtensionInit (void)
 {
@@ -254,7 +260,7 @@ RenderExtensionInit (void)
 
     extEntry = AddExtension (RENDER_NAME, 0, RenderNumberErrors,
 			     ProcRenderDispatch, SProcRenderDispatch,
-			     NULL, StandardMinorOpcode);
+			     RenderCloseDown, StandardMinorOpcode);
     if (!extEntry)
 	return;
     RenderErrBase = extEntry->errorBase;
-- 
1.7.7.6



More information about the xorg-devel mailing list