Index: /trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h	(revision 29929)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h	(revision 29930)
@@ -172,4 +172,5 @@
 
 DECLEXPORT(void) crStateInit(void);
+DECLEXPORT(void) crStateDestroy(void);
 DECLEXPORT(CRContext *) crStateCreateContext(const CRLimitsState *limits, GLint visBits, CRContext *share);
 DECLEXPORT(CRContext *) crStateCreateContextEx(const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID);
Index: /trunk/src/VBox/GuestHost/OpenGL/include/state/cr_client.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/state/cr_client.h	(revision 29929)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/state/cr_client.h	(revision 29930)
@@ -127,4 +127,5 @@
 
 DECLEXPORT(void) crStateClientInitBits(CRClientBits *c);
+DECLEXPORT(void) crStateClientDestroyBits(CRClientBits *c);
 DECLEXPORT(void) crStateClientInit(CRClientState *c);
 DECLEXPORT(void) crStateClientDestroy(CRClientState *c);
Index: /trunk/src/VBox/GuestHost/OpenGL/include/state/cr_lighting.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/state/cr_lighting.h	(revision 29929)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/state/cr_lighting.h	(revision 29930)
@@ -75,4 +75,5 @@
 
 DECLEXPORT(void) crStateLightingInitBits (CRLightingBits *l);
+DECLEXPORT(void) crStateLightingDestroyBits (CRLightingBits *l);
 DECLEXPORT(void) crStateLightingInit (CRContext *ctx);
 DECLEXPORT(void) crStateLightingDestroy (CRContext *ctx);
Index: /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_client.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_client.c	(revision 29929)
+++ /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_client.c	(revision 29930)
@@ -48,4 +48,26 @@
     for ( i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++ )
         c->a[i] = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
+#endif
+}
+
+void crStateClientDestroyBits (CRClientBits *c) 
+{
+    int i;
+
+    crFree(c->v);
+    crFree(c->n);
+    crFree(c->c);
+    crFree(c->s);
+    crFree(c->i);
+
+    for ( i = 0; i < CR_MAX_TEXTURE_UNITS; i++ )
+        crFree(c->t[i]);
+
+    crFree(c->e);
+    crFree(c->f);
+
+#ifdef CR_NV_vertex_program
+    for ( i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++ )
+        crFree(c->a[i]);
 #endif
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c	(revision 29929)
+++ /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c	(revision 29930)
@@ -249,5 +249,18 @@
 }
 
-
+void crStateDestroy(void)
+{
+    if (__currentBits)
+    {
+        crStateClientDestroyBits(&(__currentBits->client));
+        crStateLightingDestroyBits(&(__currentBits->lighting));
+        crFree(__currentBits);
+        __currentBits = NULL;
+    }
+
+#ifdef CHROMIUM_THREADSAFE
+    crFreeTSD(&__contextTSD);
+#endif
+}
 
 /*
Index: /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_lighting.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_lighting.c	(revision 29929)
+++ /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_lighting.c	(revision 29930)
@@ -14,4 +14,9 @@
 {
 	l->light = (CRLightBits *) crCalloc (sizeof(*(l->light)) * CR_MAX_LIGHTS );
+}
+
+void crStateLightingDestroyBits (CRLightingBits *l)
+{
+	crFree(l->light);
 }
 
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c	(revision 29929)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c	(revision 29930)
@@ -120,4 +120,8 @@
     cr_server.head_spu = NULL;
 #endif
+
+    crStateDestroy();
+
+    crNetTearDown();
 }
 
Index: /trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_init.c
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_init.c	(revision 29929)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_init.c	(revision 29930)
@@ -416,4 +416,8 @@
     crUnloadOpenGL();
 
+#ifdef CHROMIUM_THREADSAFE
+    crFreeTSD(&_RenderTSD);
+#endif
+
     return 1;
 }
