[libsoup] tests: fix a race in context-test
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] tests: fix a race in context-test
- Date: Fri, 20 Feb 2015 23:17:55 +0000 (UTC)
commit 4d5db071d7b8dea4ae31e5cfbe6887175c87d6c2
Author: Marc-André Lureau <marcandre lureau gmail com>
Date: Fri Feb 20 18:17:01 2015 +0100
tests: fix a race in context-test
There is a random crash due to a race when destroying the timeout
source. Although I don't quite get what the request_failed is supposed
to check, this patch fixes this race.
==25889== Invalid read of size 8
==25889== at 0x5D531E5: g_source_destroy (gmain.c:1224)
==25889== by 0x4037B4: request_failed (context-test.c:22)
==25889== by 0x5AC9F63: _g_closure_invoke_va (gclosure.c:831)
==25889== by 0x5AE3B5F: g_signal_emit_valist (gsignal.c:3218)
==25889== by 0x5AE43AE: g_signal_emit (gsignal.c:3365)
==25889== by 0x4E9C66E: soup_message_finished (soup-message.c:1141)
==25889== by 0x4EACC3A: request_finished (soup-server.c:1132)
==25889== by 0x4EA1784: soup_message_io_finished (soup-message-io.c:173)
==25889== by 0x4EAB56E: soup_server_finalize (soup-server.c:226)
==25889== by 0x5ACED85: g_object_unref (gobject.c:3170)
==25889== by 0x40583F: soup_test_server_quit_unref (test-utils.c:509)
==25889== by 0x4045DB: main (context-test.c:352)
==25889== Address 0x7be1c30 is 32 bytes inside a block of size 104 free'd
==25889== at 0x4C2ACE9: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==25889== by 0x5D5A7FE: g_free (gmem.c:190)
==25889== by 0x5D51D57: g_source_unref_internal (gmain.c:2032)
==25889== by 0x5D54C1F: g_main_dispatch (gmain.c:3138)
==25889== by 0x5D54C1F: g_main_context_dispatch (gmain.c:3710)
==25889== by 0x5D54E87: g_main_context_iterate.isra.29 (gmain.c:3781)
==25889== by 0x5D551B1: g_main_loop_run (gmain.c:3975)
==25889== by 0x4050E4: run_server_thread (test-utils.c:311)
==25889== by 0x5D7B7B4: g_thread_proxy (gthread.c:764)
==25889== by 0x6D4F529: start_thread (pthread_create.c:310)
==25889== by 0x614479C: clone (clone.S:109)
https://bugzilla.gnome.org/show_bug.cgi?id=744861
tests/context-test.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/tests/context-test.c b/tests/context-test.c
index d20a78d..567512f 100644
--- a/tests/context-test.c
+++ b/tests/context-test.c
@@ -14,12 +14,12 @@ typedef struct {
} SlowData;
static void
-request_failed (SoupMessage *msg, gpointer data)
+request_finished (SoupMessage *msg, gpointer data)
{
SlowData *sd = data;
- if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code))
- g_source_destroy (sd->timeout);
+ g_source_destroy (sd->timeout);
+ g_source_unref (sd->timeout);
g_free (sd);
}
@@ -67,8 +67,9 @@ server_callback (SoupServer *server, SoupMessage *msg,
sd->timeout = soup_add_timeout (
g_main_context_get_thread_default (),
200, add_body_chunk, sd);
+ g_source_ref (sd->timeout);
g_signal_connect (msg, "finished",
- G_CALLBACK (request_failed), sd);
+ G_CALLBACK (request_finished), sd);
}
/* Test 1: An async session in another thread with its own
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]