add: XFree(vinfo);
context: RCreateContext(Display *dpy, int screen_number, RContextAttributes *attribs){    RContext *context;    XGCValues gcv;        RErrorString[0]=0;    context = malloc(sizeof(RContext));    if (!context) {	sprintf(RErrorString, "out of memory");	return NULL;    }    memset(context, 0, sizeof(RContext));    context->dpy = dpy;        context->screen_number = screen_number;        context->attribs = malloc(sizeof(RContextAttributes));    if (!context->attribs) {	free(context);	sprintf(RErrorString, "out of memory");	return NULL;    }    if (!attribs)	*context->attribs = DEFAULT_CONTEXT_ATTRIBS;    else	*context->attribs = *attribs;    /* get configuration from environment variables */    gatherconfig(context, screen_number);        if ((context->attribs->flags & RC_VisualID)) {	XVisualInfo *vinfo, templ;	int nret;	    	templ.screen = screen_number;	templ.visualid = context->attribs->visualid;	vinfo = XGetVisualInfo(context->dpy, VisualIDMask|VisualScreenMask,			       &templ, &nret);	if (!vinfo || nret==0) {	    sprintf(RErrorString, "invalid visual id %x\n", 		    (unsigned int)context->attribs->visualid);	} else {	    if (vinfo[0].visual == DefaultVisual(dpy, screen_number)) {		context->attribs->flags |= RC_DefaultVisual;	    } else {		XSetWindowAttributes attr;		unsigned long mask;				context->visual = vinfo[0].visual;		context->depth = vinfo[0].depth;		context->vclass = vinfo[0].class;		getColormap(context, screen_number);		attr.colormap = context->cmap;                attr.override_redirect = True;		attr.border_pixel = 0;		attr.background_pixel = 0;		mask = CWBorderPixel|CWColormap|CWOverrideRedirect|CWBackPixel;		context->drawable =                    XCreateWindow(dpy, RootWindow(dpy, screen_number), 1, 1, 				  1, 1, 0, context->depth, CopyFromParent,				  context->visual, mask, &attr);/*		XSetWindowColormap(dpy, context->drawable, attr.colormap);*/	    }	    XFree(vinfo);	}    }    /* use default */    if (!context->visual) {	if ((context->attribs->flags & RC_DefaultVisual)	    || !bestContext(dpy, screen_number, context)) {	    context->visual = DefaultVisual(dpy, screen_number);	    context->depth = DefaultDepth(dpy, screen_number);	    context->cmap = DefaultColormap(dpy, screen_number);	    context->drawable = RootWindow(dpy, screen_number);	    context->black = BlackPixel(dpy, screen_number);	    context->white = WhitePixel(dpy, screen_number);	    context->vclass = context->visual->class;	}    }        gcv.function = GXcopy;    gcv.graphics_exposures = False;    context->copy_gc = XCreateGC(dpy, context->drawable, GCFunction				 |GCGraphicsExposures, &gcv);    if (context->vclass == PseudoColor || context->vclass == StaticColor) {	context->colors = allocatePseudoColor(context);	if (!context->colors) {	    return NULL;	}    } else if (context->vclass == GrayScale || context->vclass == StaticGray) {	context->colors = allocateGrayScale(context);	if (!context->colors) {	    return NULL;	}    } else if (context->vclass == TrueColor) {    	/* calc offsets to create a TrueColor pixel */	context->red_offset = count_offset(context->visual->red_mask);	context->green_offset = count_offset(context->visual->green_mask);	context->blue_offset = count_offset(context->visual->blue_mask);	/* disable dithering on 24 bits visuals */	if (context->depth >= 24)	    context->attribs->render_mode = RM_MATCH;    }        /* check avaiability of MIT-SHM */#ifdef XSHM    if (!(context->attribs->flags & RC_UseSharedMemory)) {	context->attribs->flags |= RC_UseSharedMemory;	context->attribs->use_shared_memory = True;    }    if (context->attribs->use_shared_memory) {	if (!XShmQueryExtension(context->dpy)) {	    context->attribs->use_shared_memory = False;	}    } #endif    return context;}