Skip to content

Commit

Permalink
Fix memory leak of CSTP deflated packets, and resend current pkt on r…
Browse files Browse the repository at this point in the history
…econnect

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Dec 12, 2011
1 parent b0f4d00 commit b39d347
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cstp.c
Expand Up @@ -413,10 +413,12 @@ int cstp_reconnect(struct openconnect_info *vpninfo)

openconnect_close_https(vpninfo);

/* It's already deflated in the old stream. Extremely
non-trivial to reconstitute it; just throw it away */
if (vpninfo->current_ssl_pkt == vpninfo->deflate_pkt)
/* Requeue the original packet that was deflated */
if (vpninfo->current_ssl_pkt == vpninfo->deflate_pkt) {
vpninfo->current_ssl_pkt = NULL;
queue_packet(&vpninfo->outgoing_queue, vpninfo->pending_deflated_pkt);
vpninfo->pending_deflated_pkt = NULL;
}

timeout = vpninfo->reconnect_timeout;
interval = vpninfo->reconnect_interval;
Expand Down Expand Up @@ -623,10 +625,11 @@ int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout)
return 1;
}
/* Don't free the 'special' packets */
if (vpninfo->current_ssl_pkt != vpninfo->deflate_pkt &&
vpninfo->current_ssl_pkt != &dpd_pkt &&
vpninfo->current_ssl_pkt != &dpd_resp_pkt &&
vpninfo->current_ssl_pkt != &keepalive_pkt)
if (vpninfo->current_ssl_pkt == vpninfo->deflate_pkt)
free(vpninfo->pending_deflated_pkt);
else if (vpninfo->current_ssl_pkt != &dpd_pkt &&
vpninfo->current_ssl_pkt != &dpd_resp_pkt &&
vpninfo->current_ssl_pkt != &keepalive_pkt)
free(vpninfo->current_ssl_pkt);

vpninfo->current_ssl_pkt = NULL;
Expand Down Expand Up @@ -722,6 +725,7 @@ int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout)
_("Sending compressed data packet of %d bytes\n"),
this->len);

vpninfo->pending_deflated_pkt = this;
vpninfo->current_ssl_pkt = vpninfo->deflate_pkt;
} else {
uncompr:
Expand Down
1 change: 1 addition & 0 deletions openconnect-internal.h
Expand Up @@ -146,6 +146,7 @@ struct openconnect_info {
int owe_ssl_dpd_response;
struct pkt *deflate_pkt;
struct pkt *current_ssl_pkt;
struct pkt *pending_deflated_pkt;

z_stream inflate_strm;
uint32_t inflate_adler32;
Expand Down

0 comments on commit b39d347

Please sign in to comment.