free(cd->username);
if (cd->username) { free(cd->username); }
char *ident_username(rfbClientPtr client) {	ClientData *cd = (ClientData *) client->clientData;	char *str, *newhost, *user = NULL, *newuser = NULL;	int len;	if (cd) {		user = cd->username;	}	if (!user || *user == '\0') {		char msg[128];		int n, sock, ok = 0;		if ((sock = rfbConnectToTcpAddr(client->host, 113)) < 0) {			rfbLog("could not connect to ident: %s:%d\n",			    client->host, 113);		} else {			int ret;			fd_set rfds;			struct timeval tv;			int rport = get_remote_port(client->sock);			int lport = get_local_port(client->sock);			sprintf(msg, "%d, %d\r\n", rport, lport);			n = write(sock, msg, strlen(msg));			FD_ZERO(&rfds);			FD_SET(sock, &rfds);			tv.tv_sec  = 4;			tv.tv_usec = 0;			ret = select(sock+1, &rfds, NULL, NULL, &tv); 			if (ret > 0) {				int i;				char *q, *p;				for (i=0; i<128; i++) {					msg[i] = '\0';				}				usleep(250*1000);				n = read(sock, msg, 127);				close(sock);				if (n <= 0) goto badreply;				/* 32782 , 6000 : USERID : UNIX :runge */				q = strstr(msg, "USERID");				if (!q) goto badreply;				q = strstr(q, ":");				if (!q) goto badreply;				q++;				q = strstr(q, ":");				if (!q) goto badreply;				q++;				q = lblanks(q);				p = q;				while (*p) {					if (*p == '\r' || *p == '\n') {						*p = '\0';					}					p++;				}				ok = 1;				if (strlen(q) > 24) {					*(q+24) = '\0';				}				newuser = strdup(q);				badreply:				n = 0;	/* avoid syntax error */			} else {				close(sock);			}		}		if (! ok || !newuser) {			newuser = strdup("unknown-user");		}		if (cd) {			free(cd->username);			cd->username = newuser;		}		user = newuser;	}	newhost = ip2host(client->host);	len = strlen(user) + 1 + strlen(newhost) + 1;	str = (char *) malloc(len);	sprintf(str, "%s@%s", user, newhost);	free(newhost);	return str;}