[nautilus-actions] Fix segmentation fault when saving an action



commit c974304da27da892c74aff1d615eed5ea2242add
Author: pierre <pierre vfedora10 virtuals pwi>
Date:   Mon Mar 1 13:07:11 2010 +0100

    Fix segmentation fault when saving an action
    
    It appears as unsupported to remove old children before having attached
    the new ones; NAObjectItem recursive copy so no more free children before
    copying new ones and emits a warning if list is not null.

 ChangeLog                    |   11 +++++++++++
 src/core/na-object-item.c    |    8 ++++----
 src/core/na-object.c         |    6 +-----
 src/nact/nact-main-menubar.c |   10 +++++++++-
 4 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bcc4b2e..c5f8c1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2009-03-01 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-object.c (na_object_object_reset_origin):
+	No more check for the value of object origin before resetting it.
+
+	* src/core/na-object-item.c
+	(na_object_item_remove_item): Improve debug message.
+	(copy_children): Refuse to copy when target already has	children.
+
+	* src/nact/nact-main-menubar.c
+	(nact_main_menubar_save_items): Do not re-dump all the items hierarchy.
+	(save_item): Remove old children after having created the new ones.
+
 	* src/core/na-object-action.c (ifactory_object_read_done):
 	Force toolbar label to be the same that action one if flag is set to true.
 
diff --git a/src/core/na-object-item.c b/src/core/na-object-item.c
index 9738d60..135a755 100644
--- a/src/core/na-object-item.c
+++ b/src/core/na-object-item.c
@@ -568,6 +568,7 @@ na_object_item_remove_item( NAObjectItem *item, const NAObjectId *object )
 					( void * ) item, G_OBJECT_TYPE_NAME( item ));
 
 			children = g_list_remove( children, ( gconstpointer ) object );
+			g_debug( "na_object_item_remove_item: after: children=%p, count=%u", ( void * ) children, g_list_length( children ));
 			na_object_set_items( item, children );
 		}
 	}
@@ -695,11 +696,10 @@ copy_children( NAObjectItem *target, const NAObjectItem *source )
 	NAObject *dup;
 
 	tgt_children = na_object_get_items( target );
-	g_debug( "%s: tgt_children=%p (count=%d)", thisfn, ( void * ) tgt_children, g_list_length( tgt_children ));
-
 	if( tgt_children ){
-		na_object_unref_items( tgt_children );
-		tgt_children = NULL;
+		g_warning( "%s: target_children=%p (count=%d)",
+				thisfn, ( void * ) tgt_children, g_list_length( tgt_children ));
+		g_return_if_fail( tgt_children == NULL );
 	}
 
 	src_children = na_object_get_items( source );
diff --git a/src/core/na-object.c b/src/core/na-object.c
index 19a99a0..da6da91 100644
--- a/src/core/na-object.c
+++ b/src/core/na-object.c
@@ -638,7 +638,6 @@ na_object_object_reset_origin( NAObject *object, const NAObject *origin )
 {
 	GList *origin_children, *iorig;
 	GList *object_children, *iobj;
-	NAObject *orig_object;
 
 	g_return_if_fail( NA_IS_OBJECT( origin ));
 	g_return_if_fail( NA_IS_OBJECT( object ));
@@ -647,14 +646,11 @@ na_object_object_reset_origin( NAObject *object, const NAObject *origin )
 
 		origin_children = na_object_get_items( origin );
 		object_children = na_object_get_items( object );
+
 		for( iorig = origin_children, iobj = object_children ; iorig && iobj ; iorig = iorig->next, iobj = iobj->next ){
-			orig_object = ( NAObject * ) na_object_get_origin( iorig->data );
-			g_return_if_fail( orig_object == iobj->data );
 			na_object_reset_origin( iobj->data, iorig->data );
 		}
 
-		orig_object = ( NAObject * ) na_object_get_origin( origin );
-		g_return_if_fail( orig_object == object );
 		na_iduplicable_set_origin( NA_IDUPLICABLE( object ), NA_IDUPLICABLE( origin ));
 		na_iduplicable_set_origin( NA_IDUPLICABLE( origin ), NULL );
 	}
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 85cc527..432b960 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -958,7 +958,6 @@ nact_main_menubar_save_items( NactMainWindow *window )
 	for( it = items ; it ; it = it->next ){
 		save_item( window, updater, NA_OBJECT_ITEM( it->data ));
 		na_object_check_status( it->data );
-		na_object_dump( it->data );
 	}
 	g_list_free( items );
 
@@ -1011,7 +1010,16 @@ save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 			g_debug( "%s: origin=%p", thisfn, ( void * ) origin );
 
 			if( origin ){
+				subitems = NULL;
+				if( NA_IS_OBJECT_ACTION( item )){
+					subitems = na_object_get_items( origin );
+					na_object_set_items( origin, NULL );
+				}
 				na_object_copy( origin, item, NA_IS_OBJECT_ACTION( item ));
+				na_object_reset_origin( item, origin );
+				if( subitems ){
+					na_object_unref_items( subitems );
+				}
 
 			} else {
 				dup_pivot = NA_OBJECT_ITEM( na_object_duplicate( item ));



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