Skip to content

Commit

Permalink
client: fix crash if no ipv6 when specifiy ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
liudongmiao committed Jun 12, 2024
1 parent 41fd27b commit 35133f8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion wss-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ static int get_sockaddr(struct wss_context *wss_context, struct sockaddr *sockad
char port[6];
struct evutil_addrinfo hints, *ai = NULL;

start:
memset(&hints, 0, sizeof(hints));
hints.ai_family = wss_context->server.ipv6 ? AF_INET6 : AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
Expand All @@ -416,7 +417,15 @@ static int get_sockaddr(struct wss_context *wss_context, struct sockaddr *sockad
return 0;
}

evutil_freeaddrinfo(ai);
if (ai) {
evutil_freeaddrinfo(ai);
}
if (wss_context->server.ipv6) {
LOGW("cannot connect6 to %s", wss_context->server.addr);
wss_context->server.ipv6 = 0;
goto start;
}
LOGW("cannot connect to %s", wss_context->server.addr);
return -1;
}

Expand Down

0 comments on commit 35133f8

Please sign in to comment.