hal: Branch 'master' - 4 commits
David Zeuthen
david at kemper.freedesktop.org
Tue Oct 10 14:47:36 PDT 2006
hald/device.c | 5 +--
hald/hald.c | 8 ++---
hald/hald_runner.c | 68 ++++++++++++++++++++++++++------------------------
hald/util.c | 6 ++--
hald/valgrind-hald.sh | 3 +-
5 files changed, 48 insertions(+), 42 deletions(-)
New commits:
diff-tree ec7b3fc5f01a75dd749d05c70ba2a842c16d3c66 (from parents)
Merge: 74720d88576d7cf19947ec3fbe4b15e9d0e373a4 1a077e580cf552b09445c06e088bdb1982f3f052
Author: David Zeuthen <davidz at redhat.com>
Date: Tue Oct 10 17:45:12 2006 -0400
Merge branch 'master' of ssh://david@git.freedesktop.org/git/hal
diff-tree 74720d88576d7cf19947ec3fbe4b15e9d0e373a4 (from cf9f235164570bb6f6667822ccfca0e4c36b5580)
Author: David Zeuthen <davidz at redhat.com>
Date: Tue Oct 10 17:45:02 2006 -0400
switch running_processes to using a list + fix a few memory leaks
diff --git a/hald/hald.c b/hald/hald.c
index 71e73bd..c30ff76 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -371,7 +371,7 @@ main (int argc, char *argv[])
openlog ("hald", LOG_PID, LOG_DAEMON);
#ifdef HALD_MEMLEAK_DBG
- g_mem_set_vtable (glib_mem_profiler_table);
+ /*g_mem_set_vtable (glib_mem_profiler_table);*/
#endif
g_type_init ();
@@ -601,9 +601,9 @@ extern int dbg_hal_device_object_delta;
static gboolean
my_shutdown2 (gpointer data)
{
- g_mem_profile ();
- sleep (10000);
- /*exit (1);*/
+ /*g_mem_profile ();*/
+ /*sleep (10000);*/
+ exit (1);
return FALSE;
}
diff --git a/hald/hald_runner.c b/hald/hald_runner.c
index 7940065..32abd9c 100644
--- a/hald/hald_runner.c
+++ b/hald/hald_runner.c
@@ -64,31 +64,26 @@ typedef struct
gpointer data2;
} RunningProcess;
-/* mapping from PID to RunningProcess */
-static GHashTable *running_processes = NULL;
-
-static gboolean
-rprd_foreach (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- gboolean remove;
- RunningProcess *rp = value;
- HalDevice *device = user_data;
-
- if (device == NULL || rp->device == device) {
- remove = TRUE;
- g_free (rp);
- }
-
- return remove;
-}
+/* list of RunningProcess */
+static GSList *running_processes = NULL;
static void
running_processes_remove_device (HalDevice *device)
{
- if (running_processes != NULL) {
- g_hash_table_foreach_remove (running_processes, rprd_foreach, device);
+ GSList *i;
+ GSList *j;
+
+ for (i = running_processes; i != NULL; i = j) {
+ RunningProcess *rp;
+
+ j = g_slist_next (i);
+ rp = i->data;
+
+ if (rp->device == device) {
+ g_free (rp);
+ running_processes = g_slist_delete_link (running_processes, i);
+ }
+
}
}
@@ -119,18 +114,23 @@ runner_server_message_handler (DBusConne
if (dbus_message_get_args (message, &error,
DBUS_TYPE_INT64, &dpid,
DBUS_TYPE_INVALID)) {
- RunningProcess *rp;
+ GSList *i;
GPid pid;
pid = (GPid) dpid;
- if (running_processes != NULL) {
- /*HAL_INFO (("Previously started process with pid %d exited", pid));*/
- rp = g_hash_table_lookup (running_processes, (gpointer) pid);
- if (rp != NULL) {
+ HAL_INFO (("Previously started process with pid %d exited", pid));
+
+ for (i = running_processes; i != NULL; i = g_slist_next (i)) {
+ RunningProcess *rp;
+
+ rp = i->data;
+
+ if (rp->pid == pid) {
rp->cb (rp->device, 0, 0, NULL, rp->data1, rp->data2);
- g_hash_table_remove (running_processes, (gpointer) pid);
g_free (rp);
+ running_processes = g_slist_delete_link (running_processes, i);
+ break;
}
}
}
@@ -200,8 +200,11 @@ hald_runner_stop_runner (void)
DBusMessage *msg;
/* Don't care about running processes anymore */
- g_hash_table_foreach_remove (running_processes, rprd_foreach, NULL);
- g_hash_table_destroy (running_processes);
+
+ HAL_INFO (("running_processes %p, num = %d", running_processes, g_slist_length (running_processes)));
+
+ g_slist_foreach (running_processes, (GFunc) g_free, NULL);
+ g_slist_free (running_processes);
running_processes = NULL;
HAL_INFO (("Killing runner with pid %d", runner_pid));
@@ -235,7 +238,7 @@ hald_runner_start_runner(void)
const char *hald_runner_path;
char *server_address;
- running_processes = g_hash_table_new (g_direct_hash, g_direct_equal);
+ running_processes = NULL;
dbus_error_init(&err);
runner_server = dbus_server_listen(DBUS_SERVER_ADDRESS, &err);
@@ -446,7 +449,7 @@ hald_runner_start (HalDevice *device, co
if (dbus_message_get_args (reply, &err,
DBUS_TYPE_INT64, &pid_from_runner,
DBUS_TYPE_INVALID)) {
- if (cb != NULL && running_processes != NULL) {
+ if (cb != NULL) {
RunningProcess *rp;
rp = g_new0 (RunningProcess, 1);
rp->pid = (GPid) pid_from_runner;
@@ -455,7 +458,8 @@ hald_runner_start (HalDevice *device, co
rp->data1 = data1;
rp->data2 = data2;
- g_hash_table_insert (running_processes, (gpointer) rp->pid, rp);
+ running_processes = g_slist_prepend (running_processes, rp);
+ HAL_INFO (("running_processes %p, num = %d", running_processes, g_slist_length (running_processes)));
}
} else {
HAL_ERROR (("Error extracting out_pid from runner's Start()"));
diff --git a/hald/util.c b/hald/util.c
index 405cc23..a1e8197 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -932,10 +932,12 @@ hal_util_strdup_valid_utf8 (const char *
count++;
}
- if (strlen(newstr) == count)
+ if (strlen(newstr) == count) {
+ g_free (newstr);
return NULL;
- else
+ } else {
return newstr;
+ }
}
void
diff --git a/hald/valgrind-hald.sh b/hald/valgrind-hald.sh
index d9f3fec..2b6a8fe 100755
--- a/hald/valgrind-hald.sh
+++ b/hald/valgrind-hald.sh
@@ -13,4 +13,5 @@ export HAL_FDI_SOURCE_PREPROBE=.local-fd
export HAL_FDI_SOURCE_INFORMATION=.local-fdi/share/hal/fdi/information
export HAL_FDI_SOURCE_POLICY=.local-fdi/share/hal/fdi/policy
-valgrind --num-callers=20 --show-reachable=yes --leak-check=yes --tool=memcheck ./hald --daemon=no --verbose=yes $@
+#valgrind --num-callers=20 --show-reachable=yes --leak-check=yes --tool=memcheck ./hald --daemon=no --verbose=yes $@
+valgrind --show-reachable=yes --tool=memcheck --leak-check=full ./hald --daemon=no --verbose=yes $@
diff-tree cf9f235164570bb6f6667822ccfca0e4c36b5580 (from parents)
Merge: ef8985ccb67b0876156742d46d687f7f2174ec68 4e6f2c6c565374ad22cc9e0ba1d44479d020a86b
Author: David Zeuthen <davidz at redhat.com>
Date: Tue Oct 10 13:54:58 2006 -0400
Merge branch 'master' of ssh://david@git.freedesktop.org/git/hal
diff-tree ef8985ccb67b0876156742d46d687f7f2174ec68 (from dbffafacbf7b9143d82547b9eabe61d1a5b8fffc)
Author: David Zeuthen <davidz at redhat.com>
Date: Tue Oct 10 01:22:18 2006 -0400
free hash table before the private object to prevent segfault
diff --git a/hald/device.c b/hald/device.c
index 15b0d8f..e0b8a7b 100644
--- a/hald/device.c
+++ b/hald/device.c
@@ -37,7 +37,6 @@
#include "logger.h"
#include "hald_runner.h"
-
struct _HalProperty {
int type;
union {
@@ -382,10 +381,10 @@ hal_device_finalize (GObject *obj)
g_free (device->private->udi);
- g_free (device->private);
-
g_hash_table_destroy (device->private->props);
+ g_free (device->private);
+
if (parent_class->finalize)
parent_class->finalize (obj);
}
More information about the hal-commit
mailing list