/*
 * -- $Header: /cec/src/nestor/servers/R3/shXlib/XFreeGC.c,v 1.1.1.1 90/04/23 09:57:54 spanachi Exp $
 */

#include "copyright.h"

/* $XConsortium: XFreeGC.c,v 11.9 88/09/06 16:07:32 jim Exp $ */
/* Copyright    Massachusetts Institute of Technology    1986	*/

/* -- MULTIPLEX Extension -- */

#include "Xlibint.h"

/* -- additional includes -- */

#include "resources.h"

XFreeGC (dpy, gc)
    register Display *dpy;
    GC gc;
    {
    register xResourceReq *req;
    register _XExtension *ext;
    LockDisplay(dpy);
    GetResReq (FreeGC, gc->gid, req);

    _XFreeExtData(gc->ext_data);
    /*
     * -- GC's are hard to handle ;
     * -- Let's try to remove the GC from the resource list. If we fail, 
     * -- free the data here.
     * -- This is necessary, because XCloseDisplay frees the default_gc's
     * -- AND we free the data again in XmuXFreeClientResources.
     * -- (Think freeing an pointer twice is unpredictable)
     */
      if( !XmuXRemoveGCInfo( dpy , gc->gid ) ) 
	Xfree( ( char * ) gc ) ; 

    ext = dpy->ext_procs;
    while (ext) {		/* call out to any extensions interested */
	if (ext->free_GC != NULL) (*ext->free_GC)(dpy, gc, &ext->codes);
	ext = ext->next;
	}    
    UnlockDisplay(dpy);
    SyncHandle();
    }
    
