NetworkManager r3662 - in trunk: . system-settings/src



Author: tambeti
Date: Tue May 13 10:16:41 2008
New Revision: 3662
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3662&view=rev

Log:
2008-05-13  Tambet Ingo  <tambet gmail com>

	* system-settings/src/nm-polkit-helpers.c (create_polkit_context): Use a
	single PolKitContext which is shared by all. PolKitContext::unref leaks
	just about everything, including all open file descriptiors and results
	in 99% cpu usage when data arrives to any of the fds that don't belong
	to any context anymore.


Modified:
   trunk/ChangeLog
   trunk/system-settings/src/nm-polkit-helpers.c

Modified: trunk/system-settings/src/nm-polkit-helpers.c
==============================================================================
--- trunk/system-settings/src/nm-polkit-helpers.c	(original)
+++ trunk/system-settings/src/nm-polkit-helpers.c	Tue May 13 10:16:41 2008
@@ -76,20 +76,24 @@
 PolKitContext *
 create_polkit_context (void)
 {
-	PolKitContext *pol_ctx;
-	PolKitError *err = NULL;
+	static PolKitContext *global_context = NULL;
+	PolKitError *err;
 
-	pol_ctx = polkit_context_new ();
-	polkit_context_set_io_watch_functions (pol_ctx, pk_io_add_watch, pk_io_remove_watch);
-	if (!polkit_context_init (pol_ctx, &err)) {
+	if (G_LIKELY (global_context))
+		return polkit_context_ref (global_context);
+
+	global_context = polkit_context_new ();
+	polkit_context_set_io_watch_functions (global_context, pk_io_add_watch, pk_io_remove_watch);
+	err = NULL;
+	if (!polkit_context_init (global_context, &err)) {
 		g_warning ("Cannot initialize libpolkit: %s", polkit_error_get_error_message (err));
 		polkit_error_free (err);
 
-		polkit_context_unref (pol_ctx);
-		pol_ctx = NULL;
+		polkit_context_unref (global_context);
+		global_context = NULL;
 	}
 
-	return pol_ctx;
+	return global_context;
 }
 
 gboolean



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]