[libsoup] valgrindage
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] valgrindage
- Date: Sun, 12 Aug 2012 00:03:59 +0000 (UTC)
commit 61b86e0724150d4b7684acd467ecb333386b8617
Author: Dan Winship <danw gnome org>
Date: Sat Aug 11 20:03:44 2012 -0400
valgrindage
libsoup/soup-client-input-stream.c | 11 ++++++
libsoup/soup-converter-wrapper.c | 17 +++++-----
libsoup/soup-io-stream.c | 2 +
libsoup/soup-message-io.c | 8 +++-
libsoup/soup-request-http.c | 9 ++---
libsoup/soup-session-async.c | 21 ++++++------
libsoup/soup-socket.c | 4 ++-
libsoup/soup-tld.c | 4 ++-
tests/coding-test.c | 12 ++++++-
tests/connection-test.c | 4 ++
tests/libsoup.supp | 61 +++++++++++++++++++++++++++++++++++-
tests/proxy-test.c | 2 +
tests/redirect-test.c | 4 ++
tests/requester-test.c | 10 +++++-
tests/timeout-test.c | 1 +
15 files changed, 138 insertions(+), 32 deletions(-)
---
diff --git a/libsoup/soup-client-input-stream.c b/libsoup/soup-client-input-stream.c
index 5c18eaa..966b940 100644
--- a/libsoup/soup-client-input-stream.c
+++ b/libsoup/soup-client-input-stream.c
@@ -47,6 +47,16 @@ soup_client_input_stream_init (SoupClientInputStream *stream)
}
static void
+soup_client_input_stream_finalize (GObject *object)
+{
+ SoupClientInputStream *cistream = SOUP_CLIENT_INPUT_STREAM (object);
+
+ g_clear_object (&cistream->priv->msg);
+
+ G_OBJECT_CLASS (soup_client_input_stream_parent_class)->finalize (object);
+}
+
+static void
soup_client_input_stream_set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
@@ -231,6 +241,7 @@ soup_client_input_stream_class_init (SoupClientInputStreamClass *stream_class)
g_type_class_add_private (stream_class, sizeof (SoupClientInputStreamPrivate));
+ object_class->finalize = soup_client_input_stream_finalize;
object_class->set_property = soup_client_input_stream_set_property;
object_class->get_property = soup_client_input_stream_get_property;
diff --git a/libsoup/soup-converter-wrapper.c b/libsoup/soup-converter-wrapper.c
index 1953229..6fa19d9 100644
--- a/libsoup/soup-converter-wrapper.c
+++ b/libsoup/soup-converter-wrapper.c
@@ -50,11 +50,20 @@ struct _SoupConverterWrapperPrivate
};
static void
+soup_converter_wrapper_init (SoupConverterWrapper *converter)
+{
+ converter->priv = G_TYPE_INSTANCE_GET_PRIVATE (converter,
+ SOUP_TYPE_CONVERTER_WRAPPER,
+ SoupConverterWrapperPrivate);
+}
+
+static void
soup_converter_wrapper_finalize (GObject *object)
{
SoupConverterWrapperPrivate *priv = SOUP_CONVERTER_WRAPPER (object)->priv;
g_clear_object (&priv->base_converter);
+ g_clear_object (&priv->msg);
G_OBJECT_CLASS (soup_converter_wrapper_parent_class)->finalize (object);
}
@@ -116,14 +125,6 @@ soup_converter_wrapper_get_property (GObject *object,
}
static void
-soup_converter_wrapper_init (SoupConverterWrapper *converter)
-{
- converter->priv = G_TYPE_INSTANCE_GET_PRIVATE (converter,
- SOUP_TYPE_CONVERTER_WRAPPER,
- SoupConverterWrapperPrivate);
-}
-
-static void
soup_converter_wrapper_class_init (SoupConverterWrapperClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
diff --git a/libsoup/soup-io-stream.c b/libsoup/soup-io-stream.c
index 74c7158..ea5ddef 100644
--- a/libsoup/soup-io-stream.c
+++ b/libsoup/soup-io-stream.c
@@ -103,6 +103,8 @@ soup_io_stream_finalize (GObject *object)
SoupIOStream *siostream = SOUP_IO_STREAM (object);
g_clear_object (&siostream->priv->base_iostream);
+ g_clear_object (&siostream->priv->istream);
+ g_clear_object (&siostream->priv->ostream);
G_OBJECT_CLASS (soup_io_stream_parent_class)->finalize (object);
}
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index eeb6755..6924e20 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -243,6 +243,7 @@ setup_body_istream (SoupMessage *msg)
"converter", wrapper,
NULL);
g_object_unref (io->body_istream);
+ g_object_unref (wrapper);
io->body_istream = filter;
}
@@ -908,7 +909,8 @@ io_run (SoupMessage *msg, gpointer user_data)
g_error_free (error);
soup_message_io_finished (msg);
- }
+ } else if (error)
+ g_error_free (error);
g_object_unref (msg);
g_clear_object (&cancellable);
@@ -946,8 +948,10 @@ soup_message_io_run_until_finish (SoupMessage *msg,
if (!io_run_until (msg,
SOUP_MESSAGE_IO_STATE_DONE,
SOUP_MESSAGE_IO_STATE_DONE,
- cancellable, error))
+ cancellable, error)) {
+ g_object_unref (msg);
return FALSE;
+ }
soup_message_io_finished (msg);
g_object_unref (msg);
diff --git a/libsoup/soup-request-http.c b/libsoup/soup-request-http.c
index 44a1f7d..4fc8220 100644
--- a/libsoup/soup-request-http.c
+++ b/libsoup/soup-request-http.c
@@ -113,12 +113,9 @@ free_send_async_data (SendAsyncData *sadata)
g_object_unref (sadata->http);
g_object_unref (sadata->simple);
- if (sadata->cancellable)
- g_object_unref (sadata->cancellable);
- if (sadata->stream)
- g_object_unref (sadata->stream);
- if (sadata->original)
- g_object_unref (sadata->original);
+ g_clear_object (&sadata->cancellable);
+ g_clear_object (&sadata->stream);
+ g_clear_object (&sadata->original);
g_slice_free (SendAsyncData, sadata);
}
diff --git a/libsoup/soup-session-async.c b/libsoup/soup-session-async.c
index 81afcf8..75929ed 100644
--- a/libsoup/soup-session-async.c
+++ b/libsoup/soup-session-async.c
@@ -543,7 +543,7 @@ send_request_finished (SoupSession *session, SoupMessageQueueItem *item)
return;
}
- mostream = g_object_get_data (G_OBJECT (item->msg), "SoupSessionAsync:ostream");
+ mostream = g_object_get_data (G_OBJECT (item->result), "SoupSessionAsync:ostream");
if (mostream) {
gpointer data;
gssize size;
@@ -576,9 +576,14 @@ send_async_spliced (GObject *source, GAsyncResult *result, gpointer user_data)
{
SoupMessageQueueItem *item = user_data;
GInputStream *istream = g_object_get_data (source, "istream");
-
GError *error = NULL;
+ /* It should be safe to call the sync close() method here since
+ * the message body has already been written.
+ */
+ g_input_stream_close (istream, NULL, NULL);
+ g_object_unref (istream);
+
/* If the message was cancelled, it will be completed via other means */
if (g_cancellable_is_cancelled (item->cancellable) ||
!item->result) {
@@ -589,14 +594,11 @@ send_async_spliced (GObject *source, GAsyncResult *result, gpointer user_data)
if (g_output_stream_splice_finish (G_OUTPUT_STREAM (source),
result, &error) == -1) {
send_request_return_result (item, NULL, error);
+ soup_message_queue_item_unref (item);
return;
}
- /* Otherwise either restarted or finished will eventually be called.
- * It should be safe to call the sync close() method here since
- * the message body has already been written.
- */
- g_input_stream_close (istream, NULL, NULL);
+ /* Otherwise either restarted or finished will eventually be called. */
do_idle_run_queue (item->session);
soup_message_queue_item_unref (item);
}
@@ -612,11 +614,10 @@ send_async_maybe_complete (SoupMessageQueueItem *item,
/* Message may be requeued, so gather the current message body... */
ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
- g_object_set_data_full (G_OBJECT (item->msg), "SoupSessionAsync:ostream",
+ g_object_set_data_full (G_OBJECT (item->result), "SoupSessionAsync:ostream",
ostream, g_object_unref);
- g_object_set_data_full (G_OBJECT (ostream), "istream",
- stream, g_object_unref);
+ g_object_set_data (G_OBJECT (ostream), "istream", stream);
/* Give the splice op its own ref on item */
soup_message_queue_item_ref (item);
diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c
index c789e64..f44cf34 100644
--- a/libsoup/soup-socket.c
+++ b/libsoup/soup-socket.c
@@ -674,8 +674,10 @@ socket_connected (SoupSocket *sock, GSocketConnection *conn, GError *error)
g_object_unref (priv->connect_cancel);
priv->connect_cancel = NULL;
- if (cancelled)
+ if (cancelled) {
+ g_clear_error (&error);
return SOUP_STATUS_CANCELLED;
+ }
}
if (error) {
diff --git a/libsoup/soup-tld.c b/libsoup/soup-tld.c
index fc7c992..8782a82 100644
--- a/libsoup/soup-tld.c
+++ b/libsoup/soup-tld.c
@@ -110,8 +110,10 @@ soup_tld_domain_is_public_suffix (const char *domain)
g_return_val_if_reached (FALSE);
base_domain = soup_tld_get_base_domain_internal (domain, 0, &error);
- if (g_strcmp0 (domain, base_domain))
+ if (g_strcmp0 (domain, base_domain)) {
+ g_clear_error (&error);
return FALSE;
+ }
if (g_error_matches (error, SOUP_TLD_ERROR, SOUP_TLD_ERROR_NO_BASE_DOMAIN)) {
g_error_free (error);
diff --git a/tests/coding-test.c b/tests/coding-test.c
index 02ec23a..cd7321e 100644
--- a/tests/coding-test.c
+++ b/tests/coding-test.c
@@ -109,7 +109,8 @@ server_callback (SoupServer *server, SoupMessage *msg,
if (!soup_header_contains (options, "empty")) {
soup_message_body_append (msg->response_body,
SOUP_MEMORY_TAKE, contents, length);
- }
+ } else
+ g_free (contents);
if (soup_header_contains (options, "trailing-junk")) {
soup_message_body_append (msg->response_body, SOUP_MEMORY_COPY,
@@ -366,6 +367,7 @@ do_single_coding_req_test (SoupRequest *req,
g_error_free (error);
errors++;
}
+ g_object_unref (stream);
check_response (msg, expected_encoding, expected_content_type, status);
g_object_unref (msg);
@@ -434,6 +436,7 @@ do_coding_req_test (void)
cmp = do_single_coding_req_test (req, "gzip", "text/plain", EXPECT_DECODED);
check_req_bodies (plain, cmp, "plain", "compressed w/ junk");
g_byte_array_free (cmp, TRUE);
+ g_object_unref (msg);
g_object_unref (req);
/* Plain text data, claim gzip with server error */
@@ -450,6 +453,7 @@ do_coding_req_test (void)
*/
check_req_bodies (plain, cmp, "plain", "mis-encoded");
g_byte_array_free (cmp, TRUE);
+ g_object_unref (msg);
g_object_unref (req);
/* Plain text data, claim deflate */
@@ -461,6 +465,7 @@ do_coding_req_test (void)
cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_DECODED);
check_req_bodies (plain, cmp, "plain", "compressed");
g_byte_array_free (cmp, TRUE);
+ g_object_unref (msg);
g_object_unref (req);
/* Plain text data, claim deflate w/ junk */
@@ -472,6 +477,7 @@ do_coding_req_test (void)
cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_DECODED);
check_req_bodies (plain, cmp, "plain", "compressed w/ junk");
g_byte_array_free (cmp, TRUE);
+ g_object_unref (msg);
g_object_unref (req);
/* Plain text data, claim deflate with server error */
@@ -483,6 +489,7 @@ do_coding_req_test (void)
cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_NOT_DECODED);
check_req_bodies (plain, cmp, "plain", "mis-encoded");
g_byte_array_free (cmp, TRUE);
+ g_object_unref (msg);
g_object_unref (req);
/* Plain text data, claim deflate (no zlib headers)*/
@@ -494,6 +501,7 @@ do_coding_req_test (void)
cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_DECODED);
check_req_bodies (plain, cmp, "plain", "compressed");
g_byte_array_free (cmp, TRUE);
+ g_object_unref (msg);
g_object_unref (req);
/* Plain text data, claim deflate with server error */
@@ -505,6 +513,7 @@ do_coding_req_test (void)
cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_NOT_DECODED);
check_req_bodies (plain, cmp, "plain", "mis-encoded");
g_byte_array_free (cmp, TRUE);
+ g_object_unref (msg);
g_object_unref (req);
g_byte_array_free (plain, TRUE);
@@ -551,6 +560,7 @@ do_coding_empty_test (void)
g_byte_array_free (body, TRUE);
g_object_unref (req);
+ soup_uri_free (uri);
soup_test_session_abort_unref (session);
}
diff --git a/tests/connection-test.c b/tests/connection-test.c
index 6ddc89c..f8ff7c1 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -335,6 +335,7 @@ do_timeout_req_test_for_session (SoupSession *session)
errors++;
g_clear_error (&error);
}
+ g_object_unref (stream);
}
if (sockets[1]) {
@@ -361,6 +362,7 @@ do_timeout_req_test_for_session (SoupSession *session)
errors++;
g_clear_error (&error);
}
+ g_object_unref (stream);
}
msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
@@ -582,6 +584,7 @@ do_non_persistent_test_for_session (SoupSession *session)
g_object_ref (msg);
soup_session_queue_message (session, msg, NULL, NULL);
g_main_loop_run (loop);
+ g_main_loop_unref (loop);
if (msg->status_code != SOUP_STATUS_OK) {
debug_printf (1, " Unexpected response: %d %s\n",
@@ -589,6 +592,7 @@ do_non_persistent_test_for_session (SoupSession *session)
errors++;
}
g_object_unref (msg);
+ g_object_unref (socket);
}
static void
diff --git a/tests/libsoup.supp b/tests/libsoup.supp
index 24c6516..ac21e96 100644
--- a/tests/libsoup.supp
+++ b/tests/libsoup.supp
@@ -321,7 +321,7 @@
...
fun:_dl_allocate_tls
...
- fun:g_thread_create_posix_impl
+ fun:g_system_thread_new
}
{
glib/filenamecharsets
@@ -342,12 +342,65 @@
fun:g_tls_backend_gnutls_store_session
}
{
+ glib/gtlssessioncache_client
+ Memcheck:Leak
+ ...
+ fun:gnutls_session_get_data2
+ fun:g_tls_client_connection_gnutls_finish_handshake
+}
+{
+ glib/gtlssessioncache_client2
+ Memcheck:Leak
+ ...
+ fun:g_bytes_new_with_free_func
+ fun:g_tls_client_connection_gnutls_finish_handshake
+}
+{
+ glib/gtlssessioncache_client3
+ Memcheck:Leak
+ ...
+ fun:g_bytes_new_take
+ fun:g_tls_client_connection_gnutls_constructed
+}
+{
+ glib/gtlssessioncache_client4
+ Memcheck:Leak
+ ...
+ fun:g_strdup_printf
+ fun:g_tls_client_connection_gnutls_constructed
+}
+{
+ glib/gtlssessioncache_server
+ Memcheck:Leak
+ ...
+ fun:g_tls_server_connection_gnutls_db_store
+}
+{
glib/cached_poll_array
Memcheck:Leak
...
fun:g_malloc_n
fun:g_main_context_iterate
}
+{
+ glib/rand
+ Memcheck:Leak
+ ...
+ fun:g_rand_new
+ fun:g_random_int_range
+}
+{
+ glib/g_cancellable_push_current
+ Memcheck:Leak
+ ...
+ fun:g_cancellable_push_current
+}
+{
+ glib/slice_thread_local
+ Memcheck:Leak
+ ...
+ fun:thread_memory_from_self
+}
# probably inlines the aggressive memcpy/memcmp
{
@@ -421,6 +474,12 @@
...
fun:intern_header_name
}
+{
+ libsoup/tlds
+ Memcheck:Leak
+ ...
+ fun:soup_tld_ensure_rules_hash_table
+}
# fixme?
diff --git a/tests/proxy-test.c b/tests/proxy-test.c
index ee0197a..94e548a 100644
--- a/tests/proxy-test.c
+++ b/tests/proxy-test.c
@@ -183,6 +183,7 @@ test_url_new_api (const char *url, int proxy, guint expected,
errors++;
g_clear_error (&error);
}
+ g_object_unref (stream);
}
debug_printf (1, " %d %s\n", msg->status_code, msg->reason_phrase);
@@ -244,6 +245,7 @@ async_proxy_test_thread (gpointer num)
g_main_context_push_thread_default (context);
run_test (GPOINTER_TO_INT (num), FALSE);
g_main_context_pop_thread_default (context);
+ g_main_context_unref (context);
return NULL;
}
diff --git a/tests/redirect-test.c b/tests/redirect-test.c
index 401eda2..3708d86 100644
--- a/tests/redirect-test.c
+++ b/tests/redirect-test.c
@@ -273,6 +273,7 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
}
g_error_free (error);
+ g_object_unref (msg);
g_object_unref (req);
debug_printf (2, "\n");
return;
@@ -280,6 +281,7 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
debug_printf (1, " could not send request: %s\n",
error->message);
g_error_free (error);
+ g_object_unref (msg);
g_object_unref (req);
errors++;
debug_printf (2, "\n");
@@ -293,6 +295,7 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
g_error_free (error);
errors++;
}
+ g_object_unref (stream);
if (msg->status_code != final_status) {
debug_printf (1, " - Expected final status of %d, got %d !\n",
@@ -300,6 +303,7 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
errors++;
}
+ g_object_unref (msg);
g_object_unref (req);
debug_printf (2, "\n");
}
diff --git a/tests/requester-test.c b/tests/requester-test.c
index b4e86ea..bc45e9f 100644
--- a/tests/requester-test.c
+++ b/tests/requester-test.c
@@ -151,6 +151,7 @@ auth_test_sent (GObject *source, GAsyncResult *res, gpointer user_data)
stream = soup_request_send_finish (SOUP_REQUEST (source), res, &error);
if (!stream) {
debug_printf (1, " send_async failed: %s\n", error->message);
+ g_clear_error (&error);
errors++;
g_main_loop_quit (loop);
return;
@@ -196,8 +197,8 @@ test_sent (GObject *source, GAsyncResult *res, gpointer user_data)
} else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
debug_printf (1, " send_async failed with wrong error: %s\n", error->message);
errors++;
- g_clear_error (&error);
}
+ g_clear_error (&error);
g_main_loop_quit (loop);
return;
} else {
@@ -234,6 +235,7 @@ request_started (SoupSession *session, SoupMessage *msg,
{
SoupSocket **save_socket = user_data;
+ g_clear_object (save_socket);
*save_socket = g_object_ref (socket);
}
@@ -280,6 +282,7 @@ do_async_test (SoupSession *session, SoupURI *uri,
msg->status_code, msg->reason_phrase,
expected_status);
g_object_unref (msg);
+ g_object_unref (socket);
errors++;
return;
}
@@ -459,15 +462,17 @@ do_sync_request (SoupSession *session, SoupRequest *request,
} else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
debug_printf (1, " send failed with wrong error: %s\n", error->message);
errors++;
- g_clear_error (&error);
}
+ g_clear_error (&error);
g_object_unref (msg);
+ g_object_unref (socket);
return;
} else if (!in) {
debug_printf (1, " soup_request_send failed: %s\n",
error->message);
g_object_unref (msg);
g_clear_error (&error);
+ g_object_unref (socket);
errors++;
return;
}
@@ -477,6 +482,7 @@ do_sync_request (SoupSession *session, SoupRequest *request,
msg->reason_phrase);
g_object_unref (msg);
g_object_unref (in);
+ g_object_unref (socket);
errors++;
return;
}
diff --git a/tests/timeout-test.c b/tests/timeout-test.c
index 5c9d6a8..9d9b2d1 100644
--- a/tests/timeout-test.c
+++ b/tests/timeout-test.c
@@ -152,6 +152,7 @@ do_request_to_session (SoupRequester *requester, const char *uri,
error->message);
errors++;
}
+ g_object_unref (stream);
}
if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code) &&
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]