From d705d0589f6d348c1a12b9444bb5faf9edcf0509 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 20 Nov 2006 21:47:04 +0000 Subject: [PATCH] Patch from Andrew W. Nosenko: * libsoup/soup-message-client-io.c (parse_response_headers): Avoid memory leak when parse_response_headers() is called on a message that has a 'reason_phrase' already for some reason. * libsoup/soup-gnutls.c (soup_gnutls_free): Avoid memory leak: hostname was not freed. (soup_ssl_wrap_iochannel): Avoid memory leak: SoupGNUTLSChannel 'chan' was not freed in case of initialization error. Avoid double close of the "real" (plain, non-ssl) channel FD. * libsoup/soup-socket.c (soup_socket_start_proxy_ssl): Avoid memory leak: the "real" (plain, non-ssl) GIOChannel was never "finally" unreffed (one more *_ref() than *_unref()) in case of ssl-wrapping. --- ChangeLog | 19 +++++++++++++++++++ libsoup/soup-gnutls.c | 5 ++--- libsoup/soup-message-client-io.c | 2 ++ libsoup/soup-socket.c | 7 +++++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index df36631..7d6bbd8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,24 @@ 2006-11-20 Dan Winship + Patch from Andrew W. Nosenko: + + * libsoup/soup-message-client-io.c (parse_response_headers): Avoid + memory leak when parse_response_headers() is called on a message + that has a 'reason_phrase' already for some reason. + + * libsoup/soup-gnutls.c (soup_gnutls_free): Avoid memory leak: + hostname was not freed. + (soup_ssl_wrap_iochannel): Avoid memory leak: SoupGNUTLSChannel + 'chan' was not freed in case of initialization error. Avoid double + close of the "real" (plain, non-ssl) channel FD. + + * libsoup/soup-socket.c (soup_socket_start_proxy_ssl): Avoid + memory leak: the "real" (plain, non-ssl) GIOChannel was never + "finally" unreffed (one more *_ref() than *_unref()) in case of + ssl-wrapping. + +2006-11-20 Dan Winship + * libsoup/soup-connection-ntlm.c (send_request): * libsoup/soup-session-sync.c (queue_message): * libsoup/soup-status.c (reason_phrases): Add some missing diff --git a/libsoup/soup-gnutls.c b/libsoup/soup-gnutls.c index 6ceab63..e399a6f 100644 --- a/libsoup/soup-gnutls.c +++ b/libsoup/soup-gnutls.c @@ -292,6 +292,7 @@ soup_gnutls_free (GIOChannel *channel) SoupGNUTLSChannel *chan = (SoupGNUTLSChannel *) channel; g_io_channel_unref (chan->real_sock); gnutls_deinit (chan->session); + g_free (chan->hostname); g_free (chan); } @@ -379,8 +380,6 @@ soup_ssl_wrap_iochannel (GIOChannel *sock, SoupSSLType type, goto THROW_CREATE_ERROR; } - chan = g_new0 (SoupGNUTLSChannel, 1); - ret = gnutls_init (&session, (type == SOUP_SSL_TYPE_CLIENT) ? GNUTLS_CLIENT : GNUTLS_SERVER); if (ret) @@ -398,6 +397,7 @@ soup_ssl_wrap_iochannel (GIOChannel *sock, SoupSSLType type, gnutls_transport_set_ptr (session, GINT_TO_POINTER (sockfd)); + chan = g_new0 (SoupGNUTLSChannel, 1); chan->fd = sockfd; chan->real_sock = sock; chan->session = session; @@ -409,7 +409,6 @@ soup_ssl_wrap_iochannel (GIOChannel *sock, SoupSSLType type, gchan = (GIOChannel *) chan; gchan->funcs = &soup_gnutls_channel_funcs; g_io_channel_init (gchan); - g_io_channel_set_close_on_unref (gchan, TRUE); gchan->is_readable = gchan->is_writeable = TRUE; gchan->use_buffer = FALSE; diff --git a/libsoup/soup-message-client-io.c b/libsoup/soup-message-client-io.c index bb0f9f6..109d976 100644 --- a/libsoup/soup-message-client-io.c +++ b/libsoup/soup-message-client-io.c @@ -28,6 +28,8 @@ parse_response_headers (SoupMessage *req, SoupHttpVersion version; GHashTable *resp_hdrs; + g_free((char*)req->reason_phrase); + req->reason_phrase = NULL; if (!soup_headers_parse_response (headers, headers_len, req->response_headers, &version, diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c index 6d9f6bc..3de3c51 100644 --- a/libsoup/soup-socket.c +++ b/libsoup/soup-socket.c @@ -779,10 +779,11 @@ soup_socket_start_proxy_ssl (SoupSocket *sock, const char *ssl_host) { SoupSocketPrivate *priv = SOUP_SOCKET_GET_PRIVATE (sock); GIOChannel *ssl_chan; + GIOChannel *real_chan; - get_iochannel (priv); + real_chan = get_iochannel (priv); ssl_chan = soup_ssl_wrap_iochannel ( - priv->iochannel, priv->is_server ? + real_chan, priv->is_server ? SOUP_SSL_TYPE_SERVER : SOUP_SSL_TYPE_CLIENT, ssl_host, priv->ssl_creds); @@ -790,6 +791,8 @@ soup_socket_start_proxy_ssl (SoupSocket *sock, const char *ssl_host) return FALSE; priv->iochannel = ssl_chan; + g_io_channel_unref (real_chan); + return TRUE; } -- 2.7.4