aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlava Monich <slava.monich@jolla.com>2014-09-03 11:31:59 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2014-09-05 15:25:11 +0300
commitdec0dd7691a09adfa4648b4edf674e2083e529e3 (patch)
tree87e2788ed5a854f2932f3e38d5f0b54198393fb4
parent5259e42367e2ca8f8dbaf245b8c56bdf2284799a (diff)
downloadpacrunner-dec0dd7691a09adfa4648b4edf674e2083e529e3.tar.gz
client: Detach threads since they are never joined
Unless the threads are created as detached (or joined, which is not the case here), not all resources will be released when the thread exits. If not handled, this causes unlimited memory usage over time.
-rw-r--r--src/client.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/client.c b/src/client.c
index d354c2b..f339bcb 100644
--- a/src/client.c
+++ b/src/client.c
@@ -84,6 +84,8 @@ static DBusMessage *find_proxy_for_url(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
struct jsrun_data *jsrun;
+ pthread_attr_t attrs;
+ int err;
jsrun = g_try_new0(struct jsrun_data, 1);
if (!jsrun)
@@ -94,7 +96,14 @@ static DBusMessage *find_proxy_for_url(DBusConnection *conn,
jsrun->conn = dbus_connection_ref(conn);
jsrun->msg = dbus_message_ref(msg);
- if (pthread_create(&jsrun->thread, NULL, jsrun_thread, jsrun) != 0) {
+ pthread_attr_init(&attrs);
+ pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
+
+ err = pthread_create(&jsrun->thread, &attrs, jsrun_thread, jsrun);
+
+ pthread_attr_destroy(&attrs);
+
+ if (err != 0) {
jsrun_free(jsrun);
return g_dbus_create_error(msg,
PACRUNNER_ERROR_INTERFACE ".Failed",