cursors[use]->rfb = NULL;
int get_xfixes_cursor(int init) {	static unsigned long last_cursor = 0;	static int last_index = 0;	static time_t curs_times[CURS_MAX];	static unsigned long curs_index[CURS_MAX];	int which = CURS_ARROW;	if (init) {		/* zero out our cache (cursors are not freed) */		int i;		for (i=0; i<CURS_MAX; i++) {			curs_times[i] = 0;			curs_index[i] = 0;		}		last_cursor = 0;		last_index = 0;		return -1;	}	if (xfixes_present) {#if LIBVNCSERVER_HAVE_LIBXFIXES		int use, oldest, i;		time_t oldtime, now;		XFixesCursorImage *xfc;		if (! got_xfixes_cursor_notify && xfixes_base_event_type) {			/* try again for XFixesCursorNotify event */			XEvent xev;			X_LOCK;			if (XCheckTypedEvent(dpy, xfixes_base_event_type +			    XFixesCursorNotify, &xev)) {				got_xfixes_cursor_notify++;			}			X_UNLOCK;		}		if (! got_xfixes_cursor_notify) {			/* evidently no cursor change, just return last one */			if (last_index) {				return last_index;			} else {				return CURS_ARROW;			}		}		got_xfixes_cursor_notify = 0;		/* retrieve the cursor info + pixels from server: */		X_LOCK;		xfc = XFixesGetCursorImage(dpy);		X_UNLOCK;		if (! xfc) {			/* failure. */			return(which);		}		if (xfc->cursor_serial == last_cursor) {			/* same serial index: no change */			X_LOCK;			XFree(xfc);			X_UNLOCK;			if (last_index) {				return last_index;			} else {				return CURS_ARROW;			}		}		oldest = CURS_DYN_MIN;		oldtime = curs_times[oldest];		now = time(0);		for (i = CURS_DYN_MIN; i <= CURS_DYN_MAX; i++) {			if (curs_times[i] < oldtime) {				/* watch for oldest one to overwrite */				oldest = i;				oldtime = curs_times[i];			}			if (xfc->cursor_serial == curs_index[i]) {				/*				 * got a hit with an existing cursor,				 * use that one.				 */				last_cursor = curs_index[i];				curs_times[i] = now;				last_index = i;				X_LOCK;				XFree(xfc);				X_UNLOCK;				return last_index;			}		}		/* we need to create the cursor and overwrite oldest */		use = oldest;		if (cursors[use]->rfb) {			/* clean up oldest if it exists */			if (cursors[use]->rfb->richSource) {				free(cursors[use]->rfb->richSource);			}			if (cursors[use]->rfb->alphaSource) {				free(cursors[use]->rfb->alphaSource);			}			if (cursors[use]->rfb->source) {				free(cursors[use]->rfb->source);			}			if (cursors[use]->rfb->mask) {				free(cursors[use]->rfb->mask);			}			free(cursors[use]->rfb);		}		/* place cursor into our collection */		cursors[use]->rfb = pixels2curs(xfc->pixels, xfc->width,		    xfc->height, xfc->xhot, xfc->yhot, bpp/8);		/* update time and serial index: */		curs_times[use] = now;		curs_index[use] = xfc->cursor_serial;		last_index = use;		last_cursor = xfc->cursor_serial;		which = last_index;		X_LOCK;		XFree(xfc);		X_UNLOCK;#endif	}	return(which);}