summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2014-07-22 14:04:44 -0400
committerColin Walters <walters@verbum.org>2014-07-23 13:31:02 -0400
commit7009e317d84f661ec63b85edb436d3a2727be488 (patch)
treea3f03370d5f58010bc120a1fd0eec79af85daec3
parent627b49b39039d43a784fa9890f473d1ca8d52417 (diff)
gtlsinteraction: Hoist precondition before allocation
We're using a precondition in the middle of the function, and if we hit it, we leak the closure. Let's allocate the closure per path; this allows us to allocate it before path-specific preconditions, and better avoids a pointless malloc/free pair in the unhandled case. https://bugzilla.gnome.org/show_bug.cgi?id=733576
-rw-r--r--gio/gtlsinteraction.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/gio/gtlsinteraction.c b/gio/gtlsinteraction.c
index 1df249414..ba94fe10e 100644
--- a/gio/gtlsinteraction.c
+++ b/gio/gtlsinteraction.c
@@ -372,11 +372,11 @@ g_tls_interaction_invoke_ask_password (GTlsInteraction *interaction,
g_return_val_if_fail (G_IS_TLS_PASSWORD (password), G_TLS_INTERACTION_UNHANDLED);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), G_TLS_INTERACTION_UNHANDLED);
- closure = invoke_closure_new (interaction, G_OBJECT (password), cancellable);
-
klass = G_TLS_INTERACTION_GET_CLASS (interaction);
+
if (klass->ask_password)
{
+ closure = invoke_closure_new (interaction, G_OBJECT (password), cancellable);
g_main_context_invoke (interaction->priv->context,
on_invoke_ask_password_sync, closure);
result = invoke_closure_wait_and_free (closure, error);
@@ -384,6 +384,8 @@ g_tls_interaction_invoke_ask_password (GTlsInteraction *interaction,
else if (klass->ask_password_async)
{
g_return_val_if_fail (klass->ask_password_finish, G_TLS_INTERACTION_UNHANDLED);
+
+ closure = invoke_closure_new (interaction, G_OBJECT (password), cancellable);
g_main_context_invoke (interaction->priv->context,
on_invoke_ask_password_async_as_sync, closure);
@@ -392,7 +394,6 @@ g_tls_interaction_invoke_ask_password (GTlsInteraction *interaction,
else
{
result = G_TLS_INTERACTION_UNHANDLED;
- invoke_closure_free (closure);
}
return result;
@@ -662,11 +663,11 @@ g_tls_interaction_invoke_request_certificate (GTlsInteraction *interaction,
g_return_val_if_fail (G_IS_TLS_CONNECTION (connection), G_TLS_INTERACTION_UNHANDLED);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), G_TLS_INTERACTION_UNHANDLED);
- closure = invoke_closure_new (interaction, G_OBJECT (connection), cancellable);
-
klass = G_TLS_INTERACTION_GET_CLASS (interaction);
+
if (klass->request_certificate)
{
+ closure = invoke_closure_new (interaction, G_OBJECT (connection), cancellable);
g_main_context_invoke (interaction->priv->context,
on_invoke_request_certificate_sync, closure);
result = invoke_closure_wait_and_free (closure, error);
@@ -674,6 +675,8 @@ g_tls_interaction_invoke_request_certificate (GTlsInteraction *interaction,
else if (klass->request_certificate_async)
{
g_return_val_if_fail (klass->request_certificate_finish, G_TLS_INTERACTION_UNHANDLED);
+
+ closure = invoke_closure_new (interaction, G_OBJECT (connection), cancellable);
g_main_context_invoke (interaction->priv->context,
on_invoke_request_certificate_async_as_sync, closure);
@@ -682,7 +685,6 @@ g_tls_interaction_invoke_request_certificate (GTlsInteraction *interaction,
else
{
result = G_TLS_INTERACTION_UNHANDLED;
- invoke_closure_free (closure);
}
return result;