We cannot pass the wp_context directly to callback
because the network might have been disconnected
already and wp_context would have been freed already in
that case.
---
src/wispr.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/src/wispr.c b/src/wispr.c
index 7ee5188..cbd8c7b 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -783,12 +783,38 @@ static void proxy_callback(const char *proxy, void
*user_data)
wispr_portal_request_portal(wp_context);
}
+struct cb_context_helper {
+ int index;
+ enum connman_ipconfig_type type;
+};
+
static gboolean no_proxy_callback(gpointer user_data)
{
- struct connman_wispr_portal_context *wp_context = user_data;
+ struct cb_context_helper *helper = user_data;
+ struct connman_wispr_portal_context *wp_context = NULL;
+ struct connman_wispr_portal *wispr_portal;
+
+ wispr_portal = g_hash_table_lookup(wispr_portal_list,
+ GINT_TO_POINTER(helper->index));
+ if (wispr_portal == NULL)
+ goto cleanup;
+
+ switch (helper->type) {
+ case CONNMAN_IPCONFIG_TYPE_IPV4:
+ wp_context = wispr_portal->ipv4_context;
+ break;
+ case CONNMAN_IPCONFIG_TYPE_IPV6:
+ wp_context = wispr_portal->ipv6_context;
+ break;
+ case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+ goto cleanup;
+ }
proxy_callback("DIRECT", wp_context);
+cleanup:
+ g_free(helper);
+
return FALSE;
}
@@ -876,7 +902,24 @@ static int wispr_portal_detect(struct
connman_wispr_portal_context *wp_context)
free_connman_wispr_portal_context(wp_context);
}
} else {
- g_timeout_add_seconds(0, no_proxy_callback, wp_context);
+ struct cb_context_helper *helper;
+
+ helper = g_try_new(struct cb_context_helper, 1);
+ if (helper == NULL)
+ goto done;
+
+ helper->index = if_index;
+ helper->type = wp_context->type;
+
+ /*
+ * We cannot pass the wp_context directly to callback
+ * because the network might have been disconnected
+ * already and wp_context would have been freed already in
+ * that case. So in the callback we check if the
+ * context can be found using given index.
+ */
+
+ g_timeout_add_seconds(0, no_proxy_callback, helper);
}
done:
--
1.7.11.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman