Re: [evolution-patches] memory leaks, calendar/addressbook, evo/eds




Update of the eds patch, this fixes locking on failure; not that you're not already rooted totally if this fails.

On Wed, 2005-03-09 at 18:28 +0800, Not Zed wrote:

These patches address:
- major leaks in calendar (multi-megabytes)
- reduce memory usage in addressbook, for multiple local addressbooks (multi-megabytes)
- another 'minor' leak in calendar

These are the major leaks that seem to be present at this time in the codebase.


Index: addressbook/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/ChangeLog,v
retrieving revision 1.256
diff -u -p -r1.256 ChangeLog
--- addressbook/ChangeLog	2 Mar 2005 02:58:13 -0000	1.256
+++ addressbook/ChangeLog	9 Mar 2005 10:35:07 -0000
@@ -1,3 +1,10 @@
+2005-03-09  Not Zed  <NotZed Ximian com>
+
+	* backends/file/e-book-backend-file.c
+	(e_book_backend_file_load_source): use a single global ref-counted
+	db-env for all opened db's.
+	(e_book_backend_file_dispose): clean up the env when finished.
+
 2005-03-01  Not Zed  <NotZed Ximian com>
 
 	** See bug #72878
Index: addressbook/backends/file/e-book-backend-file.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/backends/file/e-book-backend-file.c,v
retrieving revision 1.29
diff -u -p -r1.29 e-book-backend-file.c
--- addressbook/backends/file/e-book-backend-file.c	6 Feb 2005 12:28:41 -0000	1.29
+++ addressbook/backends/file/e-book-backend-file.c	9 Mar 2005 10:35:07 -0000
@@ -71,6 +71,12 @@ struct _EBookBackendFilePrivate {
 	EBookBackendSummary *summary;
 };
 
+static GStaticMutex global_env_lock = G_STATIC_MUTEX_INIT;
+static struct {
+	int ref_count;
+	DB_ENV *env;
+} global_env;
+
 static void
 string_to_dbt(const char *str, DBT *dbt)
 {
@@ -1037,14 +1043,34 @@ e_book_backend_file_load_source (EBookBa
 		return GNOME_Evolution_Addressbook_OtherError;
 	}
 
-	db_error = db_env_create (&env, 0);
-	if (db_error != 0) {
-		g_warning ("db_env_create failed with %d", db_error);
-		return GNOME_Evolution_Addressbook_OtherError;
+	g_static_mutex_lock(&global_env_lock);
+	if (global_env.ref_count > 0) {
+		env = global_env.env;
+		global_env.ref_count++;
+	} else {
+		db_error = db_env_create (&env, 0);
+		if (db_error != 0) {
+			g_warning ("db_env_create failed with %d", db_error);
+			g_static_mutex_unlock(&global_env_lock);
+			return GNOME_Evolution_Addressbook_OtherError;
+		}
+
+		db_error = env->open (env, NULL, DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_THREAD, 0);
+		if (db_error != 0) {
+			env->close(env, 0);
+			g_warning ("db_env_open failed with %d", db_error);
+			g_static_mutex_unlock(&global_env_lock);
+			return GNOME_Evolution_Addressbook_OtherError;
+		}
+
+		env->set_errcall (env, file_errcall);
+
+		global_env.env = env;
+		global_env.ref_count = 1;
 	}
-	env->open (env, NULL, DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_THREAD, 0);
+	g_static_mutex_unlock(&global_env_lock);
 
-	env->set_errcall (env, file_errcall);
+	bf->priv->env = env;
 
 	db_error = db_create (&db, env, 0);
 	if (db_error != 0) {
@@ -1271,8 +1297,13 @@ e_book_backend_file_dispose (GObject *ob
 		if (bf->priv->file_db)
 			bf->priv->file_db->close (bf->priv->file_db, 0);
 
-		if (bf->priv->env)
-			bf->priv->env->close (bf->priv->env, 0);
+		g_static_mutex_lock(&global_env_lock);
+		global_env.ref_count--;
+		if (global_env.ref_count == 0) {
+			global_env.env->close(global_env.env, 0);
+			global_env.env = NULL;
+		}
+		g_static_mutex_unlock(&global_env_lock);
 
 		if (bf->priv->summary)
 			g_object_unref(bf->priv->summary);
Index: calendar/libical/ChangeLog
===================================================================
RCS file: /cvs/gnome/libical/ChangeLog,v
retrieving revision 1.169
diff -u -p -r1.169 ChangeLog
--- calendar/libical/ChangeLog	12 Jan 2005 08:45:34 -0000	1.169
+++ calendar/libical/ChangeLog	9 Mar 2005 10:35:08 -0000
@@ -1,3 +1,7 @@
+2005-03-09  Not Zed  <NotZed Ximian com>
+
+	* src/libical/icaltime.c (unset_tz): uncomment out free'ing code.
+
 2005-01-08  Not Zed  <NotZed Ximian com>
 
 	* src/libicalss/icalfileset.c (icalfileset_read_from_file)
Index: calendar/libical/src/libical/icaltime.c
===================================================================
RCS file: /cvs/gnome/libical/src/libical/icaltime.c,v
retrieving revision 1.34
diff -u -p -r1.34 icaltime.c
--- calendar/libical/src/libical/icaltime.c	22 Dec 2004 11:54:39 -0000	1.34
+++ calendar/libical/src/libical/icaltime.c	9 Mar 2005 10:35:08 -0000
@@ -347,8 +347,8 @@ void unset_tz(char *tzstr)
     } 
 
     /* Free any previous TZ environment string we have used. */
-    //if (saved_tz)
-    //  free (saved_tz);
+    if (saved_tz)
+	free (saved_tz);
 
     /* Save a pointer to the TZ string we just set, so we can free it later.
        (This can possibly be NULL if there was no TZ to restore.) */


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