marlin r1327 - in trunk: marlin src src/dialogs
- From: iain svn gnome org
- To: svn-commits-list gnome org
- Subject: marlin r1327 - in trunk: marlin src src/dialogs
- Date: Thu, 23 Oct 2008 00:53:02 +0000 (UTC)
Author: iain
Date: Thu Oct 23 00:53:02 2008
New Revision: 1327
URL: http://svn.gnome.org/viewvc/marlin?rev=1327&view=rev
Log:
Fix memory leak when closing the undo history dialog by freeing the
history list
Modified:
trunk/marlin/ChangeLog
trunk/marlin/marlin-undo-manager.c
trunk/marlin/marlin-undo-manager.h
trunk/src/ChangeLog
trunk/src/dialogs/marlin-undo-history-dialog.c
Modified: trunk/marlin/marlin-undo-manager.c
==============================================================================
--- trunk/marlin/marlin-undo-manager.c (original)
+++ trunk/marlin/marlin-undo-manager.c Thu Oct 23 00:53:02 2008
@@ -142,9 +142,6 @@
manager = MARLIN_UNDO_MANAGER (object);
priv = manager->priv;
- if (priv == NULL) {
- return;
- }
for (p = priv->contexts; p; p = p->next) {
MarlinUndoContext *ctxt = p->data;
@@ -152,10 +149,6 @@
}
g_list_free (priv->contexts);
- manager->priv = NULL;
-
- g_free (priv);
-
G_OBJECT_CLASS (marlin_undo_manager_parent_class)->finalize (object);
}
@@ -224,6 +217,14 @@
manager->priv = g_new0 (MarlinUndoManagerPrivate, 1);
}
+/**
+ * marlin_undo_manager_new:
+ *
+ * Create a new #MarlinUndoManager object which keeps track of undo/redo
+ * state.
+ *
+ * Return value: Creates a #MarlinUndoManager object
+ */
MarlinUndoManager *
marlin_undo_manager_new (void)
{
@@ -233,20 +234,44 @@
return manager;
}
+/**
+ * marlin_undo_manager_can_undo:
+ * @manager: A #MarlinUndoManager object
+ *
+ * Checks whether @manager is able to undo.
+ *
+ * Return value: #TRUE if @manager can undo, #FALSE otherwise
+ */
gboolean
marlin_undo_manager_can_undo (MarlinUndoManager *manager)
{
return (manager->priv->undo != NULL);
}
+/**
+ * marlin_undo_manager_can_redo:
+ * @manager: A #MarlinUndoManager object
+ *
+ * Checks whether @manager is able to redo.
+ *
+ * Return value: #TRUE if @manager can redo, #FALSE otherwise
+ */
gboolean
marlin_undo_manager_can_redo (MarlinUndoManager *manager)
{
return (manager->priv->redo != NULL);
}
-/* FIXME: Should these return copies of the names
+/* FIXME: Should these return copies of the names
so that they're threadsafe? */
+/**
+ * marlin_undo_manager_get_undo_name:
+ * @manager: A #MarlinUndoManager object
+ *
+ * Gets the name of the next MarlinUndoContext that will be undone.
+ *
+ * Return value: A string that should not be freed
+ */
const char *
marlin_undo_manager_get_undo_name (MarlinUndoManager *manager)
{
@@ -258,6 +283,14 @@
}
}
+/**
+ * marlin_undo_manager_get_redo_name:
+ * @manager: A #MarlinUndoManager object
+ *
+ * Gets the name of the next MarlinUndoContext that will be redone.
+ *
+ * Return value: A string that should not be freed
+ */
const char *
marlin_undo_manager_get_redo_name (MarlinUndoManager *manager)
{
@@ -269,14 +302,25 @@
}
}
+/**
+ * marlin_undo_manager_context_begin:
+ * @manager: A #MarlinUndoManager object
+ * @name: The name of the MarlinUndoContext
+ *
+ */
MarlinUndoContext *
marlin_undo_manager_context_begin (MarlinUndoManager *manager,
- const char *name)
+ const char *name)
{
MarlinUndoContext *ctxt;
+ /* If the manager is already in the middle of a context
+ just return the current context */
if (manager->priv->working != NULL) {
WRITE_LOCK (manager->priv->working->lock);
+
+ /* Increment the ref count so that the context will not
+ be destroyed with context_end */
manager->priv->working->count++;
WRITE_UNLOCK (manager->priv->working->lock);
@@ -359,7 +403,6 @@
void
marlin_undo_manager_undo (MarlinUndoManager *manager)
{
-
if (manager->priv->undo) {
context_undo ((MarlinUndoContext *) manager->priv->undo->data);
manager->priv->redo = manager->priv->undo;
@@ -381,6 +424,16 @@
}
}
+/**
+ * marlin_undo_manager_get_history:
+ * @manager: A #MarlinUndoManager object
+ *
+ * Creates a list of #MarlinUndoHistory<!-- --> structures that represent the
+ * #MarlinUndoContext<!-- -->'s in @manager.
+ *
+ * Return value: A #GList of #MarlinUndoHistory<!-- --> structures that should
+ * be freed with #marlin_undo_manager_free_history_list.
+ */
GList *
marlin_undo_manager_get_history (MarlinUndoManager *manager)
{
@@ -420,8 +473,29 @@
}
void
+marlin_undo_manager_free_history_list (GList *history_list)
+{
+ GList *h;
+
+ for (h = history_list; h; h = h->next) {
+ MarlinUndoHistory *history = h->data;
+ g_free (history->name);
+ g_free (history);
+ }
+
+ g_list_free (history_list);
+}
+
+/**
+ * marlin_undo_context_add:
+ * @ctxt: A #MarlinUndoContext
+ * @undoable: A #MarlinUndoable
+ *
+ * Add @undoable to @ctxt.
+ */
+void
marlin_undo_context_add (MarlinUndoContext *ctxt,
- MarlinUndoable *undoable)
+ MarlinUndoable *undoable)
{
WRITE_LOCK (ctxt->lock);
ctxt->undoables = g_list_prepend (ctxt->undoables, undoable);
Modified: trunk/marlin/marlin-undo-manager.h
==============================================================================
--- trunk/marlin/marlin-undo-manager.h (original)
+++ trunk/marlin/marlin-undo-manager.h Thu Oct 23 00:53:02 2008
@@ -79,4 +79,5 @@
void marlin_undo_manager_redo (MarlinUndoManager *manager);
GList *marlin_undo_manager_get_history (MarlinUndoManager *manager);
+void marlin_undo_manager_free_history_list (GList *history_list);
#endif
Modified: trunk/src/dialogs/marlin-undo-history-dialog.c
==============================================================================
--- trunk/src/dialogs/marlin-undo-history-dialog.c (original)
+++ trunk/src/dialogs/marlin-undo-history-dialog.c Thu Oct 23 00:53:02 2008
@@ -130,6 +130,8 @@
}
}
+ marlin_undo_manager_free_history_list (history);
+
if (current) {
g_signal_handlers_block_matched (uhd->selection,
G_SIGNAL_MATCH_FUNC,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]