From 3ff207f7e34b79fb58759b063d841dbeb383c7c7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 25 May 2020 17:24:36 +0200 Subject: quiche: clean up memory properly when failing to connect Addresses the quiche side of #5447 Reported-by: Peter Wu Closes #5450 --- lib/vquic/quiche.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'lib/vquic') diff --git a/lib/vquic/quiche.c b/lib/vquic/quiche.c index 45c39925f..83815e037 100644 --- a/lib/vquic/quiche.c +++ b/lib/vquic/quiche.c @@ -89,18 +89,24 @@ static int quiche_perform_getsock(const struct connectdata *conn, return quiche_getsock((struct connectdata *)conn, socks); } -static CURLcode quiche_disconnect(struct connectdata *conn, - bool dead_connection) +static CURLcode qs_disconnect(struct quicsocket *qs) { - struct quicsocket *qs = conn->quic; - (void)dead_connection; - quiche_h3_config_free(qs->h3config); - quiche_h3_conn_free(qs->h3c); + if(qs->h3config) + quiche_h3_config_free(qs->h3config); + if(qs->h3c) + quiche_h3_conn_free(qs->h3c); quiche_config_free(qs->cfg); quiche_conn_free(qs->conn); return CURLE_OK; } +static CURLcode quiche_disconnect(struct connectdata *conn, + bool dead_connection) +{ + struct quicsocket *qs = conn->quic; + (void)dead_connection; + return qs_disconnect(qs); +} static unsigned int quiche_conncheck(struct connectdata *conn, unsigned int checks_to_perform) { @@ -284,11 +290,11 @@ CURLcode Curl_quic_is_connected(struct connectdata *conn, int sockindex, result = process_ingress(conn, sockfd, qs); if(result) - return result; + goto error; result = flush_egress(conn, sockfd, qs); if(result) - return result; + goto error; if(quiche_conn_is_established(qs->conn)) { *done = TRUE; @@ -297,6 +303,9 @@ CURLcode Curl_quic_is_connected(struct connectdata *conn, int sockindex, } return result; + error: + qs_disconnect(qs); + return result; } static CURLcode process_ingress(struct connectdata *conn, int sockfd, -- cgit v1.2.3