Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
liudongmiao committed Apr 7, 2024
1 parent 1fa3bc4 commit 53e4479
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions wss-proxy-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ static void udp_timeout_cb(evutil_socket_t sock, short event, void *ctx) {
if (event & EV_TIMEOUT) {
struct bufferevent *raw = ctx;
LOGD("udp timeout for peer %d", get_peer_port(raw));
raw_event_cb(raw, BEV_EVENT_EOF, get_wss(raw));
raw->errorcb(raw, BEV_EVENT_EOF, get_wss(raw));
}
}

Expand Down Expand Up @@ -465,6 +465,7 @@ static void udp_read_cb_client(evutil_socket_t sock, short event, void *ctx) {
struct udp_context *context = ctx;
struct bufferevent_udp key, *data;
struct udp_frame udp_frame;
struct timeval one_minute = {60, 0};
(void) event;
key.sockaddr = (struct sockaddr *) &(key.sockaddr_storage);
for (;;) {
Expand All @@ -477,6 +478,7 @@ static void udp_read_cb_client(evutil_socket_t sock, short event, void *ctx) {
break;
}
evbuffer_add(data->be.input, &udp_frame, size + UDP_FRAME_LENGTH_SIZE);
event_add(&(data->be.ev_read), &one_minute);
}
}

Expand Down Expand Up @@ -597,8 +599,8 @@ int main() {
}

extra_port = find_option_port("extra-listen-port", 0);
memset(&extra_server_context, 0, sizeof(server_context));
if (extra_port > 0) {
memset(&extra_server_context, 0, sizeof(server_context));
memcpy(&extra_raw_addr, &raw_addr, socklen);
set_port(&extra_raw_addr, extra_port);
if (init_server_context(&extra_server_context, base, &wss_context,
Expand Down
4 changes: 3 additions & 1 deletion wss-proxy-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,20 @@ static void udp_read_cb_server(evutil_socket_t sock, short event, void *ctx) {
struct evhttp_connection *wss = get_wss(raw);
if (event & EV_TIMEOUT) {
LOGD("udp timeout for peer %d", get_http_port(wss));
raw_event_cb(raw, BEV_EVENT_EOF, wss);
raw->errorcb(raw, BEV_EVENT_EOF, wss);
} else if (event & EV_READ) {
struct udp_frame udp_frame;
ev_socklen_t socklen;
struct sockaddr_storage sockaddr;
struct timeval one_minute = {60, 0};
for (;;) {
ssize_t size;
socklen = sizeof(struct sockaddr_storage);
if ((size = udp_read(sock, &udp_frame, (struct sockaddr *) &sockaddr, &socklen)) < 0) {
break;
}
evbuffer_add(raw->input, &udp_frame, size + UDP_FRAME_LENGTH_SIZE);
event_add(&(raw->ev_read), &one_minute);
}
}
}
Expand Down

0 comments on commit 53e4479

Please sign in to comment.