summaryrefslogtreecommitdiff
path: root/usr/src/cmd/bhyve/rfb.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/bhyve/rfb.c')
-rw-r--r--usr/src/cmd/bhyve/rfb.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/usr/src/cmd/bhyve/rfb.c b/usr/src/cmd/bhyve/rfb.c
index f9cc9ed9c3..36795e3690 100644
--- a/usr/src/cmd/bhyve/rfb.c
+++ b/usr/src/cmd/bhyve/rfb.c
@@ -278,8 +278,10 @@ rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd)
rc->enc_raw_ok = true;
break;
case RFB_ENCODING_ZLIB:
- rc->enc_zlib_ok = true;
- deflateInit(&rc->zstream, Z_BEST_SPEED);
+ if (!rc->enc_zlib_ok) {
+ deflateInit(&rc->zstream, Z_BEST_SPEED);
+ rc->enc_zlib_ok = true;
+ }
break;
case RFB_ENCODING_RESIZE:
rc->enc_resize_ok = true;
@@ -979,7 +981,7 @@ rfb_init(char *hostname, int port, int wait, char *password)
int e;
char servname[6];
struct rfb_softc *rc;
- struct addrinfo *ai;
+ struct addrinfo *ai = NULL;
struct addrinfo hints;
int on = 1;
#ifndef WITHOUT_CAPSICUM
@@ -994,6 +996,7 @@ rfb_init(char *hostname, int port, int wait, char *password)
sizeof(uint32_t));
rc->crc_width = RFB_MAX_WIDTH;
rc->crc_height = RFB_MAX_HEIGHT;
+ rc->sfd = -1;
rc->password = password;
@@ -1013,28 +1016,25 @@ rfb_init(char *hostname, int port, int wait, char *password)
if ((e = getaddrinfo(hostname, servname, &hints, &ai)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
- return(-1);
+ goto error;
}
rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0);
if (rc->sfd < 0) {
perror("socket");
- freeaddrinfo(ai);
- return (-1);
+ goto error;
}
setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if (bind(rc->sfd, ai->ai_addr, ai->ai_addrlen) < 0) {
perror("bind");
- freeaddrinfo(ai);
- return (-1);
+ goto error;
}
if (listen(rc->sfd, 1) < 0) {
perror("listen");
- freeaddrinfo(ai);
- return (-1);
+ goto error;
}
#ifndef WITHOUT_CAPSICUM
@@ -1063,6 +1063,16 @@ rfb_init(char *hostname, int port, int wait, char *password)
freeaddrinfo(ai);
return (0);
+
+ error:
+ if (ai != NULL)
+ freeaddrinfo(ai);
+ if (rc->sfd != -1)
+ close(rc->sfd);
+ free(rc->crc);
+ free(rc->crc_tmp);
+ free(rc);
+ return (-1);
}
#ifndef __FreeBSD__