It is now a string which must be free'd with g_free().
A return of NULL will always be interpreted as "DIRECT", so no need to
return g_strdup("DIRECT");
This means that __pacrunner_mozjs_execute() is no longer returning a pointer
to a character array which may disappear at any time if GC happens.
---
src/client.c | 9 +++++++--
src/manual.c | 17 ++++-------------
src/mozjs.c | 6 +++---
src/pacrunner.h | 8 ++++----
src/proxy.c | 8 ++++----
5 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/src/client.c b/src/client.c
index 13ad678..9acfd93 100644
--- a/src/client.c
+++ b/src/client.c
@@ -45,7 +45,9 @@ static void jsrun_free(gpointer data)
static gpointer jsrun_thread(gpointer data)
{
struct jsrun_data *jsrun = data;
- const char *sender, *url, *host, *result;
+ const char *sender, *url, *host;
+ char *result;
+ static char direct[] = "DIRECT";
sender = dbus_message_get_sender(jsrun->msg);
@@ -62,11 +64,14 @@ static gpointer jsrun_thread(gpointer data)
DBG("result %s", result);
if (result == NULL)
- result = "DIRECT";
+ result = direct;
g_dbus_send_reply(jsrun->conn, jsrun->msg, DBUS_TYPE_STRING, &result,
DBUS_TYPE_INVALID);
+ if (result != direct)
+ g_free(result);
+
jsrun_free(jsrun);
g_thread_exit(NULL);
diff --git a/src/manual.c b/src/manual.c
index dc5efd4..b97849b 100644
--- a/src/manual.c
+++ b/src/manual.c
@@ -25,34 +25,25 @@
#include "pacrunner.h"
-static char *last_result;
-
-const char *__pacrunner_manual_execute(const char *url, const char *host,
- char **servers, char **exludes)
+char *__pacrunner_manual_execute(const char *url, const char *host,
+ char **servers, char **exludes)
{
DBG("url %s host %s", url, host);
if (servers == NULL || servers[0] == NULL)
- return "DIRECT";
-
- g_free(last_result);
- last_result = g_strdup_printf("PROXY %s", servers[0]);
+ return NULL;
- return last_result;
+ return g_strdup_printf("PROXY %s", servers[0]);
}
int __pacrunner_manual_init(void)
{
DBG("");
- last_result = NULL;
-
return 0;
}
void __pacrunner_manual_cleanup(void)
{
DBG("");
-
- g_free(last_result);
}
diff --git a/src/mozjs.c b/src/mozjs.c
index 8471816..39fc3d4 100644
--- a/src/mozjs.c
+++ b/src/mozjs.c
@@ -210,7 +210,7 @@ int __pacrunner_mozjs_set_proxy(struct pacrunner_proxy
*proxy)
return 0;
}
-const char *__pacrunner_mozjs_execute(const char *url, const char *host)
+char *__pacrunner_mozjs_execute(const char *url, const char *host)
{
JSBool result;
jsval rval, args[2];
@@ -219,7 +219,7 @@ const char *__pacrunner_mozjs_execute(const char *url,
const char *host)
DBG("url %s host %s", url, host);
if (jsctx == NULL)
- return "DIRECT";
+ return NULL;
tmpurl = JS_strdup(jsctx, url);
tmphost = JS_strdup(jsctx, host);
@@ -249,7 +249,7 @@ const char *__pacrunner_mozjs_execute(const char *url,
const char *host)
if (result) {
answer = JS_GetStringBytes(JS_ValueToString(jsctx, rval));
- return answer;
+ return g_strdup(answer);
}
return NULL;
diff --git a/src/pacrunner.h b/src/pacrunner.h
index a3a8104..2ec772e 100644
--- a/src/pacrunner.h
+++ b/src/pacrunner.h
@@ -70,7 +70,7 @@ int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy,
int pacrunner_proxy_enable(struct pacrunner_proxy *proxy);
int pacrunner_proxy_disable(struct pacrunner_proxy *proxy);
-const char *pacrunner_proxy_lookup(const char *url, const char *host);
+char *pacrunner_proxy_lookup(const char *url, const char *host);
int __pacrunner_proxy_init(void);
void __pacrunner_proxy_cleanup(void);
@@ -91,10 +91,10 @@ void __pacrunner_client_cleanup();
int __pacrunner_manual_init(void);
void __pacrunner_manual_cleanup(void);
-const char *__pacrunner_manual_execute(const char *url, const char *host,
- char **servers, char **exludes);
+char *__pacrunner_manual_execute(const char *url, const char *host,
+ char **servers, char **exludes);
int __pacrunner_mozjs_init(void);
void __pacrunner_mozjs_cleanup(void);
int __pacrunner_mozjs_set_proxy(struct pacrunner_proxy *proxy);
-const char *__pacrunner_mozjs_execute(const char *url, const char *host);
+char *__pacrunner_mozjs_execute(const char *url, const char *host);
diff --git a/src/proxy.c b/src/proxy.c
index 8570c9c..301f358 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -294,7 +294,7 @@ int pacrunner_proxy_disable(struct pacrunner_proxy *proxy)
return 0;
}
-const char *pacrunner_proxy_lookup(const char *url, const char *host)
+char *pacrunner_proxy_lookup(const char *url, const char *host)
{
GList *list;
struct pacrunner_proxy *selected_proxy = NULL;
@@ -302,7 +302,7 @@ const char *pacrunner_proxy_lookup(const char *url, const
char *host)
DBG("url %s host %s", url, host);
if (proxy_list == NULL)
- return "DIRECT";
+ return NULL;
g_static_mutex_lock(&proxy_mutex);
@@ -320,7 +320,7 @@ const char *pacrunner_proxy_lookup(const char *url, const
char *host)
g_static_mutex_unlock(&proxy_mutex);
if (selected_proxy == NULL)
- return "DIRECT";
+ return NULL;
switch (selected_proxy->method) {
case PACRUNNER_PROXY_METHOD_UNKNOWN:
@@ -334,7 +334,7 @@ const char *pacrunner_proxy_lookup(const char *url, const
char *host)
return __pacrunner_mozjs_execute(url, host);
}
- return "DIRECT";
+ return NULL;
}
int __pacrunner_proxy_init(void)
--
1.7.3.2
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman