cpw.nader.asynclogging-3: 81059be9: Added purple_log_list_free and purple_lo...

morshed.nader at gmail.com morshed.nader at gmail.com
Sun Jan 23 01:15:57 EST 2011


----------------------------------------------------------------------
Revision: 81059be9b99a1e22f4cdf2052c71d1c9f7f8f6a5
Parent:   4c2f2ae22de0a0f80742a4af887eca3253e3575a
Author:   morshed.nader at gmail.com
Date:     01/19/11 03:02:02
Branch:   im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/81059be9b99a1e22f4cdf2052c71d1c9f7f8f6a5

Changelog: 

Added purple_log_list_free and purple_log_list_copy to fix up the potential memory leaks in log.c
Dropped the #include <stdio.h> from log.h
Fixed the logviewer's html markup being broken for the title label
Removed the purple_log_common_is_removable stuff from commonlog.c

Changes against parent 4c2f2ae22de0a0f80742a4af887eca3253e3575a

  patched  finch/gntlog.c
  patched  libpurple/commonlog.c
  patched  libpurple/log.c
  patched  libpurple/log.h
  patched  libpurple/oldlog.c
  patched  pidgin/gtklog.c

-------------- next part --------------
============================================================
--- libpurple/log.c	742a6ed2fbf33ccb9ddb314db2a0033a06120120
+++ libpurple/log.c	abc3b75be17a9868f6b125eed0ee2e30786c1b25
@@ -1020,7 +1020,8 @@ get_logs_thread(GSimpleAsyncResult *simp
 	if (logs == NULL && error != NULL)
 		g_simple_async_result_set_from_error(simple, error);
 	else
-		g_simple_async_result_set_op_res_gpointer(simple, logs, NULL);
+		g_simple_async_result_set_op_res_gpointer(simple, logs,
+			(GDestroyNotify) purple_log_list_free);
 
 	g_clear_error(&error);
 }
@@ -1057,7 +1058,7 @@ purple_log_real_get_logs_finish(PurpleLo
 static GList *
 purple_log_real_get_logs_finish(PurpleLog *log, GAsyncResult *res, GError **error)
 {
-	return g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(res));
+	return purple_log_list_copy(g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(res)));
 }
 
 GList *
@@ -1099,8 +1100,7 @@ purple_logs_get_logs(PurpleLogChatType c
 
 		if (list == NULL && err != NULL) {
 			g_propagate_error(error, err);
-			g_list_foreach(logs, (GFunc) g_object_unref, NULL);
-			g_list_free(logs);
+			purple_log_list_free(logs);
 			g_object_unref(log);
 
 			return NULL;
@@ -1153,7 +1153,7 @@ purple_logs_get_logs_finish(GAsyncResult
 	if (g_simple_async_result_propagate_error(simple, error))
 		return NULL;
 
-	return g_simple_async_result_get_op_res_gpointer(simple);
+	return purple_log_list_copy(g_simple_async_result_get_op_res_gpointer(simple));
 }
 
 GList *
@@ -1198,9 +1198,8 @@ purple_logs_get_system_logs(PurpleAccoun
 		list = purple_log_get_system_logs(log, account, cancellable, error);
 
 		if (list == NULL) {
+			purple_log_list_free(logs);
 			g_object_unref(log);
-			g_list_foreach(logs, (GFunc) g_object_unref, NULL);
-			g_list_free(logs);
 
 			return NULL;
 		}
@@ -1226,7 +1225,8 @@ list_syslog_thread(GSimpleAsyncResult *s
 	if (list == NULL && error != NULL)
 		g_simple_async_result_set_from_error(simple, error);
 	else
-		g_simple_async_result_set_op_res_gpointer(simple, list, NULL);
+		g_simple_async_result_set_op_res_gpointer(simple, list,
+			(GDestroyNotify) purple_log_list_free);
 
 	g_clear_error(&error);
 }
@@ -1288,7 +1288,7 @@ purple_log_real_list_syslog_finish(Purpl
 static GList *
 purple_log_real_list_syslog_finish(PurpleLog *log, GAsyncResult *res, GError **error)
 {
-	return g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(res));
+	return purple_log_list_copy(g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(res)));
 }
 
 GList *
@@ -1319,7 +1319,7 @@ purple_logs_get_system_logs_finish(GAsyn
 	if (g_simple_async_result_propagate_error(simple, error))
 		return NULL;
 
-	return g_simple_async_result_get_op_res_gpointer(simple);
+	return purple_log_list_copy(g_simple_async_result_get_op_res_gpointer(simple));
 }
 
 static guint
@@ -1367,9 +1367,7 @@ purple_log_get_total_size(PurpleLog *log
 			size = purple_log_get_size(log, cancellable, error);
 
 			if (size < 0) {
-				g_list_foreach(logs, (GFunc) g_object_unref, NULL);
-				g_list_free(logs);
-
+				purple_log_list_free(logs);
 				return -1;
 			}
 
@@ -1422,10 +1420,8 @@ total_size_thread(GSimpleAsyncResult *si
 
 			if (size < 0) {
 				g_simple_async_result_set_from_error(simple, error);
+				purple_log_list_free(logs);
 
-				g_list_foreach(logs, (GFunc) g_object_unref, NULL);
-				g_list_free(logs);
-
 				return;
 			}
 
@@ -1890,9 +1886,7 @@ purple_log_get_activity_score(PurpleLogC
 				size = purple_log_get_size(log, cancellable, error);
 
 				if (size < 0) {
-					g_list_foreach(logs, (GFunc) g_object_unref, NULL);
-					g_list_free(logs);
-
+					purple_log_list_free(logs);
 					return -1;
 				}
 
@@ -2111,6 +2105,27 @@ purple_log_get_log_dir(PurpleLogChatType
 	return dir;
 }
 
+GList *
+purple_log_list_copy(GList *list)
+{
+	if (list == NULL)
+		return NULL;
+
+	g_list_foreach(list, (GFunc) g_object_ref, NULL);
+
+	return g_list_copy(list);
+}
+
+void
+purple_log_list_free(GList *list)
+{
+	if (list == NULL)
+		return;
+
+	g_list_foreach(list, (GFunc) g_object_unref, NULL);
+	g_list_free(list);
+}
+
 /****************************************************************************
  * LOGGER FUNCTIONS *********************************************************
  ****************************************************************************/
@@ -2717,7 +2732,8 @@ log_get_log_sets_common_async(gint io_pr
 
 	simple = g_simple_async_result_new(NULL, cb, userdata, log_get_log_sets_common_async);
 
-	g_simple_async_result_run_in_thread(simple, log_get_log_sets_common_thread, io_priority, cancellable);
+	g_simple_async_result_run_in_thread(simple, log_get_log_sets_common_thread,
+		io_priority, cancellable);
 	g_object_unref(simple);
 }
 
@@ -2748,7 +2764,6 @@ log_list_cb(GObject *object, GAsyncResul
 	PurpleLog *log = PURPLE_LOG(object);
 	GError *error = NULL;
 	GList *list;
-	GSimpleAsyncResult *simple;
 
 	list = purple_log_get_logs_finish(log, res, &error);
 
@@ -2764,21 +2779,15 @@ log_list_cb(GObject *object, GAsyncResul
 	callback_data->counter--;
 
 	if (callback_data->counter < 1) {
-		/* Let the caller know we're done. */
-		if (callback_data->cb) {
-			simple = g_simple_async_result_new(NULL, callback_data->cb,
-				callback_data->userdata, purple_logs_get_logs_async);
+		GSimpleAsyncResult *simple = g_simple_async_result_new(NULL,
+			callback_data->cb, callback_data->userdata,
+			purple_logs_get_logs_async);
 
-			// g_simple_async_result_set_op_res_gpointer(simple, NULL, NULL);
-			g_simple_async_result_set_op_res_gpointer(simple, callback_data->logs, NULL);
-			g_simple_async_result_complete_in_idle(simple);
+		g_simple_async_result_set_op_res_gpointer(simple, callback_data->logs,
+			(GDestroyNotify) purple_log_list_free);
+		g_simple_async_result_complete_in_idle(simple);
 
-			g_object_unref(simple);
-		} else {
-			g_list_foreach(callback_data->logs, (GFunc) g_object_unref, NULL);
-			g_list_free(callback_data->logs);
-		}
-
+		g_object_unref(simple);
 		g_free(callback_data);
 	}
 }
@@ -2790,7 +2799,6 @@ log_system_list_cb(GObject *object, GAsy
 	PurpleLog *log = PURPLE_LOG(object);
 	GError *error = NULL;
 	GList *list;
-	GSimpleAsyncResult *simple;
 
 	list = purple_log_get_system_logs_finish(log, res, &error);
 
@@ -2806,20 +2814,15 @@ log_system_list_cb(GObject *object, GAsy
 	callback_data->counter--;
 
 	if (callback_data->counter < 1) {
-		/* Let the caller know we're done. */
-		if (callback_data->cb) {
-			simple = g_simple_async_result_new(NULL, callback_data->cb,
-				callback_data->userdata, purple_logs_get_system_logs_async);
+		GSimpleAsyncResult *simple = g_simple_async_result_new(NULL,
+			callback_data->cb, callback_data->userdata,
+			purple_logs_get_system_logs_async);
 
-			g_simple_async_result_set_op_res_gpointer(simple, callback_data->logs, NULL);
-			g_simple_async_result_complete_in_idle(simple);
+		g_simple_async_result_set_op_res_gpointer(simple, callback_data->logs,
+			(GDestroyNotify) purple_log_list_free);
+		g_simple_async_result_complete_in_idle(simple);
 
-			g_object_unref(simple);
-		} else {
-			g_list_foreach(callback_data->logs, (GFunc) g_object_unref, NULL);
-			g_list_free(callback_data->logs);
-		}
-
+		g_object_unref(simple);
 		g_free(callback_data);
 	}
 }
@@ -2874,7 +2877,8 @@ log_hash_cb(GObject *object, GAsyncResul
 	if (one_set == NULL) {
 		if (error->code != G_IO_ERROR_NOT_SUPPORTED)
 			purple_debug_error("log", "Error getting log sets for %s: %s\n",
-				PURPLE_LOG_GET_CLASS(log)->logger_name, error->message);
+				log != NULL ? PURPLE_LOG_GET_CLASS(log)->logger_name : "log_get_log_sets_common",
+				error->message);
 	} else {
 		g_hash_table_foreach_steal(one_set, steal_log_sets, callback_data->sets);
 		g_hash_table_destroy(one_set);
============================================================
--- libpurple/log.h	874709ef8d9a5c0380a6ddd2173e4120af2a41f7
+++ libpurple/log.h	09bbc7f1d34318ecfe37bd474ba9792bc7f7d73e
@@ -28,7 +28,6 @@
 #ifndef _PURPLE_LOG_H_
 #define _PURPLE_LOG_H_
 
-#include <stdio.h>
 #include <gio/gio.h>
 
 /** @copydoc _PurpleLog */
@@ -648,14 +647,14 @@ void purple_log_get_log_sets_async(Purpl
  *
  * @since 2.8.0
  */
-GHashTable *purple_logs_get_log_sets_finish(GAsyncResult *res, GError **error);
+GHashTable *purple_log_get_log_sets_finish(PurpleLog *log, GAsyncResult *res, GError **error);
 
 //
 GHashTable *purple_logs_get_log_sets(GCancellable *cancellable, GError **error);
 //
 void purple_logs_get_log_sets_async(gint io_priority, GCancellable *cancellable, GAsyncReadyCallback cb, gpointer userdata);
 //
-GHashTable *purple_log_get_log_sets_finish(PurpleLog *log, GAsyncResult *res, GError **error);
+GHashTable *purple_logs_get_log_sets_finish(GAsyncResult *res, GError **error);
 
 /**
  * Returns the activity score of a log, based on total size in bytes,
@@ -759,6 +758,11 @@ gchar *purple_log_get_log_dir(PurpleLogC
  */
 gchar *purple_log_get_log_dir(PurpleLogChatType type, const gchar *name, PurpleAccount *account);
 
+//
+GList *purple_log_list_copy(GList *list);
+//
+void purple_log_list_free(GList *list);
+
 /**
  * Implements GCompareFunc for #PurpleLog<!-- -->s
  *
============================================================
--- pidgin/gtklog.c	106c14ab8e3ca1756309a8b1451cb049b5cd422c
+++ pidgin/gtklog.c	283066632654085232f2da886fd3b460880d7da4
@@ -816,7 +816,7 @@ log_select_cb(GtkTreeSelection *sel, Pid
 			title = g_strdup_printf(_("Conversation with %s on %s"),
 				log_name, log_get_date(log));
 
-		bold_text = g_strdup_printf("<span size='larger' weight='bold'>%s</span", title);
+		bold_text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>", title);
 		gtk_label_set_markup(GTK_LABEL(priv->label), bold_text);
 
 		g_free(title);
@@ -1524,9 +1524,7 @@ pidgin_log_viewer_set_logs(PidginLogView
 
 	priv = PIDGIN_LOG_VIEWER_GET_PRIVATE(lv);
 
-	g_list_foreach(priv->logs, (GFunc) g_object_unref, NULL);
-	g_list_free(priv->logs);
-
+	purple_log_list_free(priv->logs);
 	priv->logs = logs;
 
 	populate_log_tree(lv);
@@ -1760,8 +1758,7 @@ pidgin_log_viewer_finalize(GObject *obje
 
 	purple_request_close_with_handle(lv);
 
-	g_list_foreach(priv->logs, (GFunc) g_object_unref, NULL);
-	g_list_free(priv->logs);
+	purple_log_list_free(priv->logs);
 	g_free(priv->search);
 
 	if (priv->search_cancel != NULL) {
@@ -2095,6 +2092,8 @@ pidgin_log_viewer_init(PidginLogViewer *
 	gtk_box_pack_start(GTK_BOX(content_area), priv->title_box, FALSE, FALSE, 0);
 
 
+	//icon?
+
 	/* Title Label */
 	priv->label = gtk_label_new(NULL);
 	gtk_misc_set_alignment(GTK_MISC(priv->label), 0, 0);
============================================================
--- finch/gntlog.c	eef3990672d63ac8f411c1c37e82711ae400e712
+++ finch/gntlog.c	d33518933aeef2ee61258db82aff711ec0740347
@@ -1065,10 +1065,9 @@ finch_log_viewer_set_logs(FinchLogViewer
 
 	priv = FINCH_LOG_VIEWER_GET_PRIVATE(lv);
 
-	g_list_foreach(priv->logs, (GFunc) g_object_unref, NULL);
-	g_list_free(priv->logs);
-
+	purple_log_list_free(priv->logs);
 	priv->logs = logs;
+
 	populate_log_tree(lv);
 
 	g_object_notify(G_OBJECT(lv), "logs");
@@ -1252,8 +1251,7 @@ finch_log_viewer_finalize(GObject *objec
 
 	purple_request_close_with_handle(lv);
 
-	g_list_foreach(priv->logs, (GFunc) g_object_unref, NULL);
-	g_list_free(priv->logs);
+	purple_log_list_free(priv->logs);
 	g_free(priv->search);
 
 	if (priv->search_cancel != NULL) {
============================================================
--- libpurple/oldlog.c	95078f43d7fb03295654348d8d64be8184467b6f
+++ libpurple/oldlog.c	b78ca5eb7dc8a643406b48055de078f5eab0dffc
@@ -174,8 +174,7 @@ purple_old_log_list(PurpleLog *log, Purp
 			/* Make sure the last read didn't have an issue */
 			if (err != NULL) {
 				g_propagate_error(error, err);
-				g_list_foreach(list, (GFunc) g_object_unref, NULL);
-				g_list_free(list);
+				purple_log_list_free(list);
 				list = NULL;
 			}
 
============================================================
--- libpurple/commonlog.c	2c2837e8f675a36c6bceb5c85bc51c466eea48c9
+++ libpurple/commonlog.c	450065a608ea4ea6b6cfa2dbf396b0adae4f4a72
@@ -62,7 +62,6 @@ static gboolean purple_log_common_remove
 static void common_thread_callback_data_free(gpointer);
 
 static gboolean purple_log_common_remove(PurpleLog *, GCancellable *, GError **);
-static gboolean purple_log_common_is_removable(PurpleLog *, GCancellable *, GError **);
 static gssize purple_log_common_size(PurpleLog *, GCancellable *, GError **);
 
 static void
@@ -79,7 +78,6 @@ purple_common_log_class_init(PurpleCommo
 	log_class->logger_id = "common";
 
 	log_class->remove_fn = purple_log_common_remove;
-	log_class->is_removable_fn = purple_log_common_is_removable;
 	log_class->size_fn = purple_log_common_size;
 
 	properties[PROP_COMMON_LOG_FILE] =
@@ -274,34 +272,6 @@ purple_log_common_remove(PurpleLog *log,
 	return result;
 }
 
-static gboolean
-purple_log_common_is_removable(PurpleLog *log, GCancellable *cancellable, GError **error)
-{
-	PurpleCommonLogPrivate *priv = PURPLE_COMMON_LOG_GET_PRIVATE(log);
-	GFileInfo *info;
-	gboolean ret;
-
-	if (priv->file == NULL) {
-		g_set_error_literal(error,
-			G_IO_ERROR,
-			G_IO_ERROR_FAILED,
-			_("Unable to get log path"));
-
-		return FALSE;
-	}
-
-	info = g_file_query_info(priv->file, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE,
-		G_FILE_QUERY_INFO_NONE, cancellable, error);
-
-	if (info == NULL)
-		return FALSE;
-
-	ret = g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE);
-	g_object_unref(info);
-
-	return ret;
-}
-
 gboolean
 purple_log_common_writer(PurpleLog *log, const gchar *ext, GCancellable *cancellable, GError **error)
 {
@@ -462,10 +432,8 @@ purple_log_common_lister(PurpleLogChatTy
 		if (g_cancellable_set_error_if_cancelled(cancellable, error)) {
 			g_dir_close(dir);
 			g_free(path);
+			purple_log_list_free(list);
 
-			g_list_foreach(list, (GFunc) g_object_unref, NULL);
-			g_list_free(list);
-
 			return NULL;
 		}
 
@@ -536,7 +504,8 @@ common_lister_thread(GSimpleAsyncResult 
 	if (list == NULL)
 		g_simple_async_result_set_from_error(simple, error);
 	else
-		g_simple_async_result_set_op_res_gpointer(simple, list, (GDestroyNotify) g_list_free);
+		g_simple_async_result_set_op_res_gpointer(simple, list,
+			(GDestroyNotify) purple_log_list_free);
 
 	g_clear_error(&error);
 }


More information about the Commits mailing list