hal/hald device.c, 1.15, 1.16 hald.c, 1.30, 1.31 hald.h, 1.7, 1.8 hald_dbus.c, 1.29, 1.30 property.c, 1.11, 1.12 valgrind-hald.sh, NONE, 1.1

David Zeuthen david at freedesktop.org
Sun Feb 27 20:53:17 PST 2005


Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv22133/hald

Modified Files:
	device.c hald.c hald.h hald_dbus.c property.c 
Added Files:
	valgrind-hald.sh 
Log Message:
2005-02-27  David Zeuthen  <davidz at redhat.com>

	More fun with valgrind :-)

	* hald/linux2/classdev.c: Fix a bunch of leaks by calling
	g_object_unref for HalDevice objects that goes away

	* hald/linux2/physdev.c: Fix a bunch of leaks by calling
	g_object_unref for HalDevice objects that goes away

	* hald/linux2/hotplug.c (hotplug_event_begin_sysfs): Don't
	leak parent_path

	* hald/linux2/coldplug.c (free_hash_sys_to_class_in_dev): New
	function; to free values of the sysfs_to_class_in_devices_map
	hashtable
	(coldplug_synthesize_events): Fix memory leaks

	* hald/linux2/blockdev.c: Fix a bunch of leaks by calling
	g_object_unref for HalDevice objects that goes away

	* hald/property.c (hal_property_set_string): Don't leak old value

	* hald/hald_dbus.c (sender_has_privileges): Fixup error handling
	(device_property_atomic_update_end): Fix memory leak

	* hald/hald.h: Add HALD_MEMLEAK_DBG but uncomment it by default

	* hald/hald.c (my_shutdown): New function, defined only if
	HALD_MEMLEAK_DBG is set; should prolly be invoked by handler
	registered with atexit(3); some day in the future
	(osspec_probe_done): Add appropriate timeout if HALD_MEMLEAK_DBG
	is et

	* hald/device.c (hal_device_finalize, hal_device_new): Recognize
	the HALD_MEMLEAK_DBG define and maintain dbg_hal_device_object_delta
	accordingly.
	(hal_device_set_udi): Don't leak old udi

	* hald/valgrind-hald.sh: New file - useful for finding memory
	leaks



Index: device.c
===================================================================
RCS file: /cvs/hal/hal/hald/device.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- device.c	26 Feb 2005 22:31:42 -0000	1.15
+++ device.c	28 Feb 2005 04:53:15 -0000	1.16
@@ -48,17 +48,27 @@
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
+#ifdef HALD_MEMLEAK_DBG
+int dbg_hal_device_object_delta = 0;
+#endif
+
 static void
 hal_device_finalize (GObject *obj)
 {
 	HalDevice *device = HAL_DEVICE (obj);
 
+#ifdef HALD_MEMLEAK_DBG
+	dbg_hal_device_object_delta--;
+	printf ("************* in finalize for udi=%s\n", device->udi);
+#endif
+
 	g_slist_foreach (device->properties, (GFunc) hal_property_free, NULL);
 
 	g_free (device->udi);
 
 	if (parent_class->finalize)
 		parent_class->finalize (obj);
+
 }
 
 static void
@@ -149,6 +159,7 @@
 	return type;
 }
 
+
 HalDevice *
 hal_device_new (void)
 {
@@ -156,6 +167,9 @@
 
 	device = g_object_new (HAL_TYPE_DEVICE, NULL);
 
+#ifdef HALD_MEMLEAK_DBG
+	dbg_hal_device_object_delta++;
+#endif
 	return device;
 }
 
@@ -398,6 +412,8 @@
 void
 hal_device_set_udi (HalDevice *device, const char *udi)
 {
+	if (device->udi != NULL)
+		g_free (device->udi);
 	device->udi = g_strdup (udi);
 }
 

Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- hald.c	28 Feb 2005 01:16:47 -0000	1.30
+++ hald.c	28 Feb 2005 04:53:15 -0000	1.31
@@ -601,10 +601,31 @@
 	return 0;
 }
 
-gboolean
-resolve_udiprop_path (const char *path, const char *source_udi,
-		      char *udi_result, size_t udi_result_size, 
-		      char *prop_result, size_t prop_result_size);
+#ifdef HALD_MEMLEAK_DBG
+extern int dbg_hal_device_object_delta;
+
+/* useful for valgrinding; see below */
+static gboolean
+my_shutdown (gpointer data)
+{
+	HalDeviceStore *gdl;
+	
+	printf ("Num devices in TDL: %d\n", g_slist_length ((hald_get_tdl ())->devices));
+	printf ("Num devices in GDL: %d\n", g_slist_length ((hald_get_gdl ())->devices));
+	
+	gdl = hald_get_gdl ();
+next:
+	if (g_slist_length (gdl->devices) > 0) {
+		HalDevice *d = HAL_DEVICE(gdl->devices->data);
+		hal_device_store_remove (gdl, d);
+		g_object_unref (d);
+		goto next;
+	}
+	
+	printf ("hal_device_object_delta = %d (should be zero)\n", dbg_hal_device_object_delta);
+	exit (1);
+}
+#endif
 
 void 
 osspec_probe_done (void)
@@ -620,6 +641,11 @@
 
 	hald_is_initialising = FALSE;
 
+#ifdef HALD_MEMLEAK_DBG
+	g_timeout_add ((HALD_MEMLEAK_DBG) * 1000,
+		       my_shutdown,
+		       NULL);
+#endif
 }
 
 

Index: hald.h
===================================================================
RCS file: /cvs/hal/hal/hald/hald.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- hald.h	31 Jan 2005 20:06:39 -0000	1.7
+++ hald.h	28 Feb 2005 04:53:15 -0000	1.8
@@ -48,6 +48,15 @@
 extern dbus_bool_t hald_is_initialising;
 extern dbus_bool_t hald_is_shutting_down;
 
+/* If this is defined, the amount of time, in seconds, before hald
+ * does an exit where resources are freed - useful for valgrinding
+ * and finding memory leaks; e.g. plug in a device, do something
+ * with the hal daemon and then look at the report
+ *
+ * Use hald/valgrind-hald.sh for this
+ */
+/*#define HALD_MEMLEAK_DBG 60*/
+
 /**
  *  @}
  */

Index: hald_dbus.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_dbus.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- hald_dbus.c	28 Feb 2005 01:16:47 -0000	1.29
+++ hald_dbus.c	28 Feb 2005 04:53:15 -0000	1.30
@@ -1110,29 +1110,34 @@
 	DBusError error;
 	unsigned long user_uid;
 	const char *user_base_svc;
+	dbus_bool_t ret;
+
+	ret = FALSE;
 
 	user_base_svc = dbus_message_get_sender (message);
 	if (user_base_svc == NULL) {
 		HAL_WARNING (("Cannot determine base service of caller"));
-		return FALSE;
+		goto out;
 	}
 
 	HAL_DEBUG (("base_svc = %s", user_base_svc));
 
 	dbus_error_init (&error);
-	if ((user_uid = dbus_bus_get_unix_user (connection, user_base_svc, &error)) 
-       == (unsigned long) -1) {
+	if ((user_uid = dbus_bus_get_unix_user (connection, user_base_svc, &error)) == (unsigned long) -1) {
 		HAL_WARNING (("Could not get uid for connection"));
-		return FALSE;
+		goto out;
 	}
 
 	HAL_INFO (("uid for caller is %ld", user_uid));
 
 	if (user_uid != 0 && user_uid != geteuid()) {
 		HAL_WARNING (("uid %d is doesn't have the right priviledges", user_uid));
-		return FALSE;
+		goto out;
 	}
 
+	ret = TRUE;
+
+out:
 	return TRUE;
 }
 
@@ -1829,8 +1834,7 @@
 	--atomic_count;
 
 	if (atomic_count < 0) {
-		HAL_WARNING (("*** atomic_count = %d < 0 !!",
-			      atomic_count));
+		HAL_WARNING (("*** atomic_count = %d < 0 !!", atomic_count));
 		atomic_count = 0;
 	}
 
@@ -1845,22 +1849,21 @@
 
 			pu_iter_next = pu_iter->next;
 
+			/* see if we've already processed this */
 			if (pu_iter->udi == NULL)
-				goto have_processed;
+				goto already_processed;
 
 			/* count number of updates for this device */
 			num_updates_this = 0;
-			for (pu_iter2 = pu_iter;
-			     pu_iter2 != NULL; pu_iter2 = pu_iter2->next) {
+			for (pu_iter2 = pu_iter; pu_iter2 != NULL; pu_iter2 = pu_iter2->next) {
 				if (strcmp (pu_iter2->udi, pu_iter->udi) == 0)
 					num_updates_this++;
 			}
 
 			/* prepare message */
-			message = dbus_message_new_signal (
-				pu_iter->udi,
-				"org.freedesktop.Hal.Device",
-				"PropertyModified");
+			message = dbus_message_new_signal (pu_iter->udi,
+							   "org.freedesktop.Hal.Device",
+							   "PropertyModified");
 			dbus_message_iter_init_append (message, &iter);
 			dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32,
 							&num_updates_this);
@@ -1898,6 +1901,7 @@
 					dbus_message_iter_close_container (&iter_array, &iter_struct);
 
 					/* signal this is already processed */
+					g_free (pu_iter2->key);
 					if (pu_iter2 != pu_iter) {
 						g_free (pu_iter2->udi);
 						pu_iter2->udi = NULL;
@@ -1905,19 +1909,18 @@
 				}
 			}
 
+			g_free (pu_iter->udi);
 			dbus_message_iter_close_container (&iter, &iter_array);
 
-
 			if (!dbus_connection_send
 			    (dbus_connection, message, NULL))
 				DIE (("error broadcasting message"));
-
 			dbus_message_unref (message);
 
-		      have_processed:
-			g_free (pu_iter->key);
+		already_processed:
 			g_free (pu_iter);
-		}		/* for all updates */
+
+		} /* for all updates */
 
 		num_pending_updates = 0;
 		pending_updates_head = NULL;

Index: property.c
===================================================================
RCS file: /cvs/hal/hal/hald/property.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- property.c	14 Feb 2005 18:20:04 -0000	1.11
+++ property.c	28 Feb 2005 04:53:15 -0000	1.12
@@ -273,6 +273,8 @@
 			  prop->type == HAL_PROPERTY_TYPE_INVALID);
 
 	prop->type = HAL_PROPERTY_TYPE_STRING;
+	if (prop->str_value != NULL)
+		g_free (prop->str_value);
 	prop->str_value = g_strdup (value);
 
 	while (!g_utf8_validate (prop->str_value, -1,

--- NEW FILE: valgrind-hald.sh ---
#!/bin/sh

export PATH=linux2:linux2/probing:linux2/addons:.:../tools:../tools/linux:$PATH
export HAL_FDI_SOURCE_PREPROBE=../fdi/preprobe
export HAL_FDI_SOURCE_INFORMATION=../fdi/information
export HAL_FDI_SOURCE_POLICY=../fdi/policy
valgrind --num-callers=20 --show-reachable=yes --leak-check=yes --tool=memcheck ./hald --daemon=no --verbose=yes --retain-privileges




More information about the hal-commit mailing list