Index: bindings/python/rb.override
===================================================================
RCS file: /cvs/gnome/rhythmbox/bindings/python/rb.override,v
retrieving revision 1.22
diff -p -u -r1.22 rb.override
--- bindings/python/rb.override	12 Jul 2006 09:56:55 -0000	1.22
+++ bindings/python/rb.override	21 Jul 2006 21:31:30 -0000
@@ -21,7 +21,7 @@ headers
 #include "rb-source.h"
 #include "rb-sourcelist.h"
 
-void pyrb_register_classes (PyObject *d); 
+void pyrb_register_classes (PyObject *d);
 void pyrb_add_constants (PyObject *module, const gchar *strip_prefix);
 
 /* hacks to deal with the nonstandard class name RHYTHMDB */
@@ -29,9 +29,9 @@ void pyrb_add_constants (PyObject *modul
 #define RHYTHMDB_RHYTHMDB(o) RHYTHMDB(o)
 
 %%
-modulename rb 
+modulename rb
 %%
-import gobject.GObject as PyGObject_Type 
+import gobject.GObject as PyGObject_Type
 import gtk.ActionGroup as PyGtkActionGroup_Type
 import gtk.Dialog as PyGtkDialog_Type
 import gtk.HBox as PyGtkHBox_Type
@@ -342,7 +342,7 @@ _wrap_RBSource__proxy_do_impl_cut (RBSou
 	}
 
 	ret = _helper_unwrap_pointer_pylist (py_retval, RHYTHMDB_TYPE_ENTRY);
-    
+
 	Py_DECREF(py_retval);
 	Py_DECREF(py_method);
 	Py_DECREF(py_self);
@@ -413,7 +413,7 @@ _wrap_RBSource__proxy_do_impl_copy (RBSo
 	}
 
 	ret = _helper_unwrap_pointer_pylist (py_retval, RHYTHMDB_TYPE_ENTRY);
-    
+
 	Py_DECREF(py_retval);
 	Py_DECREF(py_method);
 	Py_DECREF(py_self);
@@ -484,7 +484,7 @@ _wrap_RBSource__proxy_do_impl_get_proper
 	}
 
 	ret = _helper_unwrap_pointer_pylist (py_retval, RB_TYPE_PROPERTY_VIEW);
-    
+
 	Py_DECREF(py_retval);
 	Py_DECREF(py_method);
 	Py_DECREF(py_self);
@@ -555,7 +555,7 @@ _wrap_RBSource__proxy_do_impl_get_ui_act
 	}
 
 	ret = _helper_unwrap_string_pylist (py_retval);
-    
+
 	Py_DECREF(py_retval);
 	Py_DECREF(py_method);
 	Py_DECREF(py_self);
@@ -626,7 +626,7 @@ _wrap_RBSource__proxy_do_impl_get_search
 	}
 
 	ret = _helper_unwrap_string_pylist (py_retval);
-    
+
 	Py_DECREF(py_retval);
 	Py_DECREF(py_method);
 	Py_DECREF(py_self);
@@ -652,11 +652,15 @@ override rb_entry_view_get_sorting_order
 static PyObject *
 _wrap_rb_entry_view_get_sorting_order(PyGObject *self)
 {
-    const char *column = NULL;
+    char *column = NULL;
     gint order = 0;
+    PyObject *object;
 
     rb_entry_view_get_sorting_order(RB_ENTRY_VIEW(self->obj), &column, &order);
-    return Py_BuildValue ("si", column, order);
+    object = Py_BuildValue ("si", column, order);
+    g_free (column);
+
+    return object;
 }
 %%
 override rb_entry_view_set_fixed_column_width kwargs
@@ -738,7 +742,7 @@ _wrap_RBSource__proxy_do_impl_paste(RBSo
     PyObject *py_retval;
     PyObject *py_args;
     PyObject *py_method;
-    
+
     __py_state = pyg_gil_state_ensure();
     py_self = pygobject_new((GObject *) self);
     if (!py_self) {
@@ -748,11 +752,11 @@ _wrap_RBSource__proxy_do_impl_paste(RBSo
         return;
     }
     py_entries = _helper_wrap_pointer_glist (entries, RHYTHMDB_TYPE_ENTRY);
-    
+
     py_args = PyTuple_New(1);
     Py_INCREF(py_entries);
     PyTuple_SET_ITEM(py_args, 0, py_entries);
-    
+
     py_method = PyObject_GetAttrString(py_self, "do_impl_paste");
     if (!py_method) {
         if (PyErr_Occurred())
@@ -783,7 +787,7 @@ _wrap_RBSource__proxy_do_impl_paste(RBSo
         pyg_gil_state_release(__py_state);
         return;
     }
-    
+
     Py_DECREF(py_retval);
     Py_DECREF(py_method);
     Py_DECREF(py_args);
@@ -857,7 +861,7 @@ _wrap_RBSource__proxy_do_impl_get_status
     PyObject *py_retval;
     PyObject *py_method;
     const char *st, *pt;
-    
+
     __py_state = pyg_gil_state_ensure();
     py_self = pygobject_new((GObject *) self);
     if (!py_self) {
@@ -866,7 +870,7 @@ _wrap_RBSource__proxy_do_impl_get_status
         pyg_gil_state_release(__py_state);
         return;
     }
-    
+
     py_method = PyObject_GetAttrString(py_self, "do_impl_get_status");
     if (!py_method) {
         if (PyErr_Occurred())
@@ -900,7 +904,7 @@ _wrap_RBSource__proxy_do_impl_get_status
       *status_text = g_strdup (st);
     if (pt)
       *progress_text = g_strdup (pt);
-    
+
     Py_DECREF(py_retval);
     Py_DECREF(py_method);
     Py_DECREF(py_self);
Index: daapsharing/rb-daap-share.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/daapsharing/rb-daap-share.c,v
retrieving revision 1.24
diff -p -u -r1.24 rb-daap-share.c
--- daapsharing/rb-daap-share.c	17 Jul 2006 14:50:43 -0000	1.24
+++ daapsharing/rb-daap-share.c	21 Jul 2006 21:31:30 -0000
@@ -1133,6 +1133,8 @@ add_playlist_entry_to_mlcl (GtkTreeModel
 	if (client_requested (mb->bits, CONTAINER_ITEM_ID))
 		rb_daap_structure_add (mlit, RB_DAAP_CC_MCTI, (gint32) id);
 
+	rhythmdb_entry_unref (entry);
+
 	return FALSE;
 }
 
Index: plugins/rb-plugin-manager.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/plugins/rb-plugin-manager.c,v
retrieving revision 1.4
diff -p -u -r1.4 rb-plugin-manager.c
--- plugins/rb-plugin-manager.c	20 Apr 2006 20:43:23 -0000	1.4
+++ plugins/rb-plugin-manager.c	21 Jul 2006 21:31:30 -0000
@@ -1,4 +1,5 @@
-/*
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
  * heavily based on code from Gedit
  *
  * Copyright (C) 2002 Paolo Maggi and James Willcox
Index: plugins/cd-recorder/rb-cd-recorder-plugin.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/plugins/cd-recorder/rb-cd-recorder-plugin.c,v
retrieving revision 1.1
diff -p -u -r1.1 rb-cd-recorder-plugin.c
--- plugins/cd-recorder/rb-cd-recorder-plugin.c	10 Jul 2006 02:00:34 -0000	1.1
+++ plugins/cd-recorder/rb-cd-recorder-plugin.c	21 Jul 2006 21:31:30 -0000
@@ -19,9 +19,7 @@
 
 #define __EXTENSIONS__
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
 
 #include <string.h> /* For strlen */
 #include <glib/gi18n-lib.h>
@@ -220,6 +218,8 @@ playlist_row_inserted_cb (GtkTreeModel  
 	RhythmDBEntry *entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter);
 
 	playlist_entries_changed (model, entry, pi);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
Index: plugins/generic-player/rb-psp-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/plugins/generic-player/rb-psp-source.c,v
retrieving revision 1.11
diff -p -u -r1.11 rb-psp-source.c
--- plugins/generic-player/rb-psp-source.c	17 Jul 2006 14:51:41 -0000	1.11
+++ plugins/generic-player/rb-psp-source.c	21 Jul 2006 21:31:30 -0000
@@ -166,6 +166,8 @@ visit_playlist_dirs (const gchar *rel_pa
 					   RHYTHMDB_QUERY_MODEL_LIMIT_NONE, NULL,
 					   NULL, 0);
 	rb_generic_player_source_add_playlist (RB_GENERIC_PLAYER_SOURCE (source), shell, RB_SOURCE (playlist));
+	rhythmdb_query_free (query);
+
 	g_object_unref (shell);
 	g_object_unref (db);
 
Index: podcast/rb-podcast-manager.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/podcast/rb-podcast-manager.c,v
retrieving revision 1.52
diff -p -u -r1.52 rb-podcast-manager.c
--- podcast/rb-podcast-manager.c	17 Jul 2006 14:51:57 -0000	1.52
+++ podcast/rb-podcast-manager.c	21 Jul 2006 21:31:30 -0000
@@ -492,19 +492,23 @@ rb_podcast_manager_update_feeds (RBPodca
 
 static gboolean
 rb_podcast_manager_head_query_cb (GtkTreeModel *query_model,
- 	   			  GtkTreePath *path, GtkTreeIter *iter,
+ 	   			  GtkTreePath *path,
+				  GtkTreeIter *iter,
 				  RBPodcastManager *manager)
 {
         const char *uri;
-        RhythmDBEntry* entry;
+        RhythmDBEntry *entry;
 	guint status;
 
         gtk_tree_model_get (query_model, iter, 0, &entry, -1);
         uri = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
 	status = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_STATUS);
+
 	if (status == 1)
 		rb_podcast_manager_subscribe_feed (manager, uri);
 
+	rhythmdb_entry_unref (entry);
+
         return FALSE;
 }
 
@@ -548,7 +552,7 @@ rb_podcast_manager_copy_post (RBPodcastM
 
 	/* get first element of list */
 	g_mutex_lock (pd->priv->download_list_mutex);
-	data = (RBPodcastManagerInfo *) g_list_first(pd->priv->download_list)->data;
+	data = (RBPodcastManagerInfo *) g_list_first (pd->priv->download_list)->data;
 	g_mutex_unlock (pd->priv->download_list_mutex);
 
 	if (data == NULL)
@@ -1249,10 +1253,14 @@ rb_podcast_manager_db_entry_deleted_cb (
 			gboolean has_next;
 			do {
 				RhythmDBEntry *entry;
+
 				gtk_tree_model_get (query_model, &iter, 0, &entry, -1);
 				has_next = gtk_tree_model_iter_next (query_model, &iter);
 				rhythmdb_entry_delete (pd->priv->db, entry);
+				rhythmdb_entry_unref (entry);
+
 			} while (has_next);
+
 			rhythmdb_commit (pd->priv->db);
 		}
 	}
@@ -1491,9 +1499,9 @@ rb_podcast_manager_insert_feed (RBPodcas
 		g_value_set_ulong (&status, RHYTHMDB_PODCAST_STATUS_WAITING);
 		for (t = download_entries; t != NULL; t = g_list_next (t)) {
 			rhythmdb_entry_set (db,
-						       (RhythmDBEntry*) t->data,
-						       RHYTHMDB_PROP_STATUS,
-						       &status);
+					    (RhythmDBEntry*) t->data,
+					    RHYTHMDB_PROP_STATUS,
+					    &status);
 		}
 		g_value_unset (&status);
 	}
Index: rhythmdb/rb-refstring.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/rhythmdb/rb-refstring.c,v
retrieving revision 1.14
diff -p -u -r1.14 rb-refstring.c
--- rhythmdb/rb-refstring.c	14 Jul 2006 12:29:27 -0000	1.14
+++ rhythmdb/rb-refstring.c	21 Jul 2006 21:31:30 -0000
@@ -87,8 +87,8 @@ rb_refstring_new (const char *init)
 void
 rb_refstring_unref (RBRefString *val)
 {
-	if (!val)
-		return;
+	g_return_if_fail (val != NULL);
+	g_return_if_fail (val->refcount > 0);
 
 	if (g_atomic_int_dec_and_test (&val->refcount)) {
 		g_mutex_lock (rb_refstrings_mutex);
@@ -107,6 +107,9 @@ rb_refstring_system_shutdown (void)
 RBRefString *
 rb_refstring_ref (RBRefString *val)
 {
+	g_return_val_if_fail (val != NULL, NULL);
+	g_return_val_if_fail (val->refcount > 0, NULL);
+
 	g_atomic_int_inc (&val->refcount);
 	return val;
 }
@@ -161,7 +164,7 @@ rb_refstring_get_sort_key (RBRefString *
 		return NULL;
 
 	ptr = &val->sortkey;
-	string = (const char*)g_atomic_pointer_get (ptr);
+	string = (const char *)g_atomic_pointer_get (ptr);
 	if (string == NULL) {
 		char *newstring;
 		const char *s;
Index: rhythmdb/rhythmdb-private.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/rhythmdb/rhythmdb-private.h,v
retrieving revision 1.18
diff -p -u -r1.18 rhythmdb-private.h
--- rhythmdb/rhythmdb-private.h	19 Jul 2006 11:18:03 -0000	1.18
+++ rhythmdb/rhythmdb-private.h	21 Jul 2006 21:31:30 -0000
@@ -68,7 +68,7 @@ enum {
 struct RhythmDBEntry_ {
 	/* internal bits */
 	guint flags;
-	gint refcount;
+	volatile gint refcount;
 	void *data;
 	RhythmDBEntryType type;
 
Index: rhythmdb/rhythmdb-property-model.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/rhythmdb/rhythmdb-property-model.c,v
retrieving revision 1.49
diff -p -u -r1.49 rhythmdb-property-model.c
--- rhythmdb/rhythmdb-property-model.c	17 Jul 2006 14:52:12 -0000	1.49
+++ rhythmdb/rhythmdb-property-model.c	21 Jul 2006 21:31:30 -0000
@@ -338,14 +338,15 @@ rhythmdb_property_model_set_property (GO
 							      G_CALLBACK (rhythmdb_property_model_prop_changed_cb),
 							      model);
 			g_hash_table_foreach_remove (model->priv->entries, (GHRFunc)_remove_entry_cb, model);
-			g_object_unref (G_OBJECT (model->priv->query_model));
+			g_object_unref (model->priv->query_model);
 		}
 
 		model->priv->query_model = g_value_get_object (value);
 		g_assert (rhythmdb_property_model_iter_n_children (GTK_TREE_MODEL (model), NULL) == 1);
 
 		if (model->priv->query_model) {
-			g_object_ref (G_OBJECT (model->priv->query_model));
+			g_object_ref (model->priv->query_model);
+
 			g_signal_connect_object (G_OBJECT (model->priv->query_model),
 						 "row_inserted",
 						 G_CALLBACK (rhythmdb_property_model_row_inserted_cb),
@@ -375,9 +376,9 @@ rhythmdb_property_model_set_property (GO
 
 static void
 rhythmdb_property_model_get_property (GObject *object,
-				   guint prop_id,
-				   GValue *value,
-				   GParamSpec *pspec)
+				      guint prop_id,
+				      GValue *value,
+				      GParamSpec *pspec)
 {
 	RhythmDBPropertyModel *model = RHYTHMDB_PROPERTY_MODEL (object);
 
@@ -441,6 +442,7 @@ rhythmdb_property_model_finalize (GObjec
 
 	g_hash_table_destroy (model->priv->reverse_map);
 	g_sequence_free (model->priv->properties);
+
 	g_hash_table_destroy (model->priv->entries);
 
 	if (model->priv->query_model)
@@ -450,7 +452,8 @@ rhythmdb_property_model_finalize (GObjec
 }
 
 RhythmDBPropertyModel *
-rhythmdb_property_model_new (RhythmDB *db, RhythmDBPropType propid)
+rhythmdb_property_model_new (RhythmDB *db,
+			     RhythmDBPropType propid)
 {
 	return g_object_new (RHYTHMDB_TYPE_PROPERTY_MODEL, "db", db, "prop", propid, NULL);
 }
@@ -461,21 +464,28 @@ rhythmdb_property_model_row_inserted_cb 
 					 GtkTreeIter *iter,
 					 RhythmDBPropertyModel *propmodel)
 {
-	RhythmDBEntry *entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter);
+	RhythmDBEntry *entry;
 	RhythmDBPropertyModelEntry *prop;
 
-	if (g_hash_table_lookup (propmodel->priv->entries, entry))
-		return;
+	entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter);
+
+	if (g_hash_table_lookup (propmodel->priv->entries, entry)) {
+		goto out;
+	}
 
 	prop = rhythmdb_property_model_insert (propmodel, entry);
 	g_hash_table_insert (propmodel->priv->entries, entry, prop);
 
 	rhythmdb_property_model_sync (propmodel);
+ out:
+	rhythmdb_entry_unref (entry);
 }
 
 static void
-rhythmdb_property_model_prop_changed_cb (RhythmDB *db, RhythmDBEntry *entry,
-					 RhythmDBPropType propid, const GValue *old,
+rhythmdb_property_model_prop_changed_cb (RhythmDB *db,
+					 RhythmDBEntry *entry,
+					 RhythmDBPropType propid,
+					 const GValue *old,
 					 const GValue *new,
 					 RhythmDBPropertyModel *propmodel)
 {
@@ -531,7 +541,9 @@ rhythmdb_property_model_entry_removed_cb
 }
 
 static gint
-rhythmdb_property_model_compare (RhythmDBPropertyModelEntry *a, RhythmDBPropertyModelEntry *b, RhythmDBPropertyModel *model)
+rhythmdb_property_model_compare (RhythmDBPropertyModelEntry *a,
+				 RhythmDBPropertyModelEntry *b,
+				 RhythmDBPropertyModel *model)
 {
 	const char *a_str, *b_str;
 
@@ -542,7 +554,8 @@ rhythmdb_property_model_compare (RhythmD
 }
 
 static RhythmDBPropertyModelEntry *
-rhythmdb_property_model_insert (RhythmDBPropertyModel *model, RhythmDBEntry *entry)
+rhythmdb_property_model_insert (RhythmDBPropertyModel *model,
+				RhythmDBEntry *entry)
 {
 	RhythmDBPropertyModelEntry *prop;
 	GtkTreeIter iter;
@@ -631,7 +644,8 @@ rhythmdb_property_model_delete_prop (Rhy
 
 gboolean
 rhythmdb_property_model_iter_from_string (RhythmDBPropertyModel *model,
-					  const char *name, GtkTreeIter *iter)
+					  const char *name,
+					  GtkTreeIter *iter)
 {
 	GSequencePtr ptr;
 
@@ -668,7 +682,8 @@ rhythmdb_property_model_get_n_columns (G
 }
 
 static GType
-rhythmdb_property_model_get_column_type (GtkTreeModel *tree_model, int index)
+rhythmdb_property_model_get_column_type (GtkTreeModel *tree_model,
+					 int index)
 {
 	switch (index) {
 	case RHYTHMDB_PROPERTY_MODEL_COLUMN_TITLE:
@@ -684,7 +699,8 @@ rhythmdb_property_model_get_column_type 
 }
 
 static gboolean
-rhythmdb_property_model_get_iter (GtkTreeModel *tree_model, GtkTreeIter *iter,
+rhythmdb_property_model_get_iter (GtkTreeModel *tree_model,
+				  GtkTreeIter *iter,
 				  GtkTreePath *path)
 {
 	RhythmDBPropertyModel *model = RHYTHMDB_PROPERTY_MODEL (tree_model);
@@ -732,8 +748,10 @@ rhythmdb_property_model_get_path (GtkTre
 }
 
 static void
-rhythmdb_property_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter,
-				   gint column, GValue *value)
+rhythmdb_property_model_get_value (GtkTreeModel *tree_model,
+				   GtkTreeIter *iter,
+				   gint column,
+				   GValue *value)
 {
 	RhythmDBPropertyModel *model = RHYTHMDB_PROPERTY_MODEL (tree_model);
 
@@ -835,7 +853,8 @@ rhythmdb_property_model_iter_n_children 
 
 static gboolean
 rhythmdb_property_model_iter_nth_child (GtkTreeModel *tree_model,
-					GtkTreeIter *iter, GtkTreeIter *parent,
+					GtkTreeIter *iter,
+					GtkTreeIter *parent,
 					gint n)
 {
 	RhythmDBPropertyModel *model = RHYTHMDB_PROPERTY_MODEL (tree_model);
@@ -884,17 +903,18 @@ rhythmdb_property_model_drag_data_delete
 
 /*Going through hoops to avoid nested functions*/
 struct QueryModelCbStruct {
-	RhythmDB* db;
-	GString* reply;
+	RhythmDB *db;
+	GString *reply;
 };
 
 static gboolean
 query_model_cb (GtkTreeModel *query_model,
- 		GtkTreePath *path, GtkTreeIter *iter,
+ 		GtkTreePath *path,
+		GtkTreeIter *iter,
  		struct QueryModelCbStruct *data)
 {
- 	const char* uri;
- 	RhythmDBEntry* entry;
+ 	const char *uri;
+ 	RhythmDBEntry *entry;
 
  	gtk_tree_model_get (query_model, iter, 0, &entry, -1);
  	uri = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
@@ -1062,7 +1082,8 @@ rhythmdb_property_model_drag_data_get (R
 }
 
 void
-rhythmdb_property_model_enable_drag (RhythmDBPropertyModel *model, GtkTreeView *view)
+rhythmdb_property_model_enable_drag (RhythmDBPropertyModel *model,
+				     GtkTreeView *view)
 {
 	const GtkTargetEntry *targets;
 	gint n_elements;
Index: rhythmdb/rhythmdb-query-model.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/rhythmdb/rhythmdb-query-model.c,v
retrieving revision 1.138
diff -p -u -r1.138 rhythmdb-query-model.c
--- rhythmdb/rhythmdb-query-model.c	18 Jul 2006 12:37:30 -0000	1.138
+++ rhythmdb/rhythmdb-query-model.c	21 Jul 2006 21:31:30 -0000
@@ -552,15 +552,23 @@ rhythmdb_query_model_init (RhythmDBQuery
 	model->priv->stamp = g_random_int ();
 
 	model->priv->entries = g_sequence_new (NULL);
-	model->priv->reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
+	model->priv->reverse_map = g_hash_table_new_full (g_direct_hash,
+							  g_direct_equal,
+							  (GDestroyNotify)rhythmdb_entry_unref,
+							  NULL);
+
 	model->priv->limited_entries = g_sequence_new (NULL);
-	model->priv->limited_reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
+	model->priv->limited_reverse_map = g_hash_table_new_full (g_direct_hash,
+								  g_direct_equal,
+								  (GDestroyNotify)rhythmdb_entry_unref,
+								  NULL);
 
 	model->priv->reorder_drag_and_drop = FALSE;
 }
 
 static GObject *
-rhythmdb_query_model_constructor (GType type, guint n_construct_properties,
+rhythmdb_query_model_constructor (GType type,
+				  guint n_construct_properties,
 				  GObjectConstructParam *construct_properties)
 {
 	RhythmDBQueryModel *model;
@@ -617,7 +625,7 @@ rhythmdb_query_model_dispose (GObject *o
 		g_signal_handlers_disconnect_by_func (G_OBJECT (model->priv->base_model),
 						      G_CALLBACK (rhythmdb_query_model_base_entry_removed),
 						      model);
-		g_object_unref (G_OBJECT (model->priv->base_model));
+		g_object_unref (model->priv->base_model);
 		model->priv->base_model = NULL;
 	}
 
@@ -638,10 +646,9 @@ rhythmdb_query_model_finalize (GObject *
 
 	rb_debug ("finalizing query model %p", object);
 
-	g_hash_table_foreach (model->priv->reverse_map, (GHFunc) rhythmdb_entry_unref, model->priv->db);
 	g_hash_table_destroy (model->priv->reverse_map);
 	g_sequence_free (model->priv->entries);
-	g_hash_table_foreach (model->priv->limited_reverse_map, (GHFunc) rhythmdb_entry_unref, model->priv->db);
+
 	g_hash_table_destroy (model->priv->limited_reverse_map);
 	g_sequence_free (model->priv->limited_entries);
 
@@ -663,7 +670,8 @@ rhythmdb_query_model_finalize (GObject *
 }
 
 RhythmDBQueryModel *
-rhythmdb_query_model_new (RhythmDB *db, GPtrArray *query,
+rhythmdb_query_model_new (RhythmDB *db,
+			  GPtrArray *query,
 			  GCompareDataFunc sort_func,
 			  gpointer sort_data,
 			  GDestroyNotify sort_data_destroy,
@@ -722,6 +730,7 @@ rhythmdb_query_model_chain (RhythmDBQuer
 
 	if (model->priv->base_model) {
 		g_object_ref (model->priv->base_model);
+
 		g_assert (model->priv->base_model->priv->db == model->priv->db);
 
 		g_signal_connect_object (G_OBJECT (model->priv->base_model),
@@ -782,7 +791,8 @@ rhythmdb_query_model_has_pending_changes
 }
 
 static void
-rhythmdb_query_model_entry_added_cb (RhythmDB *db, RhythmDBEntry *entry,
+rhythmdb_query_model_entry_added_cb (RhythmDB *db,
+				     RhythmDBEntry *entry,
 				     RhythmDBQueryModel *model)
 {
 	if (model->priv->query) {
@@ -801,8 +811,10 @@ rhythmdb_query_model_entry_added_cb (Rhy
 }
 
 static void
-rhythmdb_query_model_entry_changed_cb (RhythmDB *db, RhythmDBEntry *entry,
-				       GSList *changes, RhythmDBQueryModel *model)
+rhythmdb_query_model_entry_changed_cb (RhythmDB *db,
+				       RhythmDBEntry *entry,
+				       GSList *changes,
+				       RhythmDBQueryModel *model)
 {
 	gboolean hidden = FALSE;
 	GSList *t;
@@ -880,7 +892,8 @@ rhythmdb_query_model_entry_changed_cb (R
 }
 
 static void
-rhythmdb_query_model_entry_deleted_cb (RhythmDB *db, RhythmDBEntry *entry,
+rhythmdb_query_model_entry_deleted_cb (RhythmDB *db,
+				       RhythmDBEntry *entry,
 				       RhythmDBQueryModel *model)
 {
 
@@ -899,14 +912,16 @@ rhythmdb_query_model_process_update (str
 		g_idle_add ((GSourceFunc) idle_process_update, update);
 }
 
-gboolean
+static gboolean
 idle_process_update (struct RhythmDBQueryModelUpdate *update)
 {
 	switch (update->type) {
 	case RHYTHMDB_QUERY_MODEL_UPDATE_ROWS_INSERTED:
 	{
 		guint i;
+
 		rb_debug ("inserting %d rows", update->entrydata.entries->len);
+
 		for (i = 0; i < update->entrydata.entries->len; i++ ) {
 			RhythmDBEntry *entry = g_ptr_array_index (update->entrydata.entries, i);
 
@@ -921,7 +936,9 @@ idle_process_update (struct RhythmDBQuer
 
 			rhythmdb_entry_unref (entry);
 		}
+
 		g_ptr_array_free (update->entrydata.entries, TRUE);
+
 		break;
 	}
 	case RHYTHMDB_QUERY_MODEL_UPDATE_ROW_INSERTED_INDEX:
@@ -937,13 +954,15 @@ idle_process_update (struct RhythmDBQuer
 	}
 
 	g_atomic_int_add (&update->model->priv->pending_update_count, -1);
-	g_object_unref (G_OBJECT (update->model));
+	g_object_unref (update->model);
 	g_free (update);
 	return FALSE;
 }
 
 void
-rhythmdb_query_model_add_entry (RhythmDBQueryModel *model, RhythmDBEntry *entry, gint index)
+rhythmdb_query_model_add_entry (RhythmDBQueryModel *model,
+				RhythmDBEntry *entry,
+				gint index)
 {
 	struct RhythmDBQueryModelUpdate *update;
 
@@ -967,8 +986,11 @@ rhythmdb_query_model_add_entry (RhythmDB
 	update->entrydata.data.index = index;
 	update->model = model;
 
-	g_object_ref (G_OBJECT (model));
+	/* take references; released in update idle */
+	g_object_ref (model);
+
 	rhythmdb_entry_ref (entry);
+
 	rhythmdb_query_model_process_update (update);
 }
 
@@ -985,9 +1007,13 @@ rhythmdb_query_model_get_duration (Rhyth
 }
 
 static void
-rhythmdb_query_model_insert_into_main_list (RhythmDBQueryModel *model, RhythmDBEntry *entry, gint index)
+rhythmdb_query_model_insert_into_main_list (RhythmDBQueryModel *model,
+					    RhythmDBEntry *entry,
+					    gint index)
 {
 	GSequencePtr ptr;
+
+	/* take reference; released when removed from hash */
 	rhythmdb_entry_ref (entry);
 
 	if (model->priv->sort_func) {
@@ -1005,7 +1031,8 @@ rhythmdb_query_model_insert_into_main_li
 			sort_data = model->priv->sort_data;
 		}
 
-		ptr = g_sequence_insert_sorted (model->priv->entries, entry,
+		ptr = g_sequence_insert_sorted (model->priv->entries,
+						entry,
 						sort_func,
 						sort_data);
 	} else {
@@ -1019,6 +1046,7 @@ rhythmdb_query_model_insert_into_main_li
 		ptr = g_sequence_ptr_prev (ptr);
 	}
 
+	/* the hash now owns this reference to the entry */
 	g_hash_table_insert (model->priv->reverse_map, entry, ptr);
 
 	model->priv->total_duration += rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION);
@@ -1026,10 +1054,12 @@ rhythmdb_query_model_insert_into_main_li
 }
 
 static void
-rhythmdb_query_model_insert_into_limited_list (RhythmDBQueryModel *model, RhythmDBEntry *entry)
+rhythmdb_query_model_insert_into_limited_list (RhythmDBQueryModel *model,
+					       RhythmDBEntry *entry)
 {
 	GSequencePtr ptr;
 
+	/* take reference; released when removed from hash */
 	rhythmdb_entry_ref (entry);
 
 	if (model->priv->sort_func) {
@@ -1056,11 +1086,13 @@ rhythmdb_query_model_insert_into_limited
 		ptr = g_sequence_ptr_prev (ptr);
 	}
 
+	/* the hash now owns this reference to the entry */
 	g_hash_table_insert (model->priv->limited_reverse_map, entry, ptr);
 }
 
 static void
-rhythmdb_query_model_remove_from_main_list (RhythmDBQueryModel *model, RhythmDBEntry *entry)
+rhythmdb_query_model_remove_from_main_list (RhythmDBQueryModel *model,
+					    RhythmDBEntry *entry)
 {
 	GSequencePtr ptr = g_hash_table_lookup (model->priv->reverse_map, entry);
 	int index;
@@ -1077,21 +1109,29 @@ rhythmdb_query_model_remove_from_main_li
 	model->priv->total_duration -= rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION);
 	model->priv->total_size -= rhythmdb_entry_get_uint64 (entry, RHYTHMDB_PROP_FILE_SIZE);
 
+	/* take temporary ref */
+	rhythmdb_entry_ref (entry);
+
 	g_sequence_remove (ptr);
 	g_assert (g_hash_table_remove (model->priv->reverse_map, entry));
 
 	g_signal_emit (G_OBJECT (model), rhythmdb_query_model_signals[POST_ENTRY_DELETE], 0, entry);
 
+	/* release temporary ref */
 	rhythmdb_entry_unref (entry);
 }
 
 static void
-rhythmdb_query_model_remove_from_limited_list (RhythmDBQueryModel *model, RhythmDBEntry *entry)
+rhythmdb_query_model_remove_from_limited_list (RhythmDBQueryModel *model,
+					       RhythmDBEntry *entry)
 {
 	GSequencePtr ptr = g_hash_table_lookup (model->priv->limited_reverse_map, entry);
 
+	/* take temporary ref */
+	rhythmdb_entry_ref (entry);
 	g_sequence_remove (ptr);
 	g_hash_table_remove (model->priv->limited_reverse_map, entry);
+	/* release temporary ref */
 	rhythmdb_entry_unref (entry);
 }
 
@@ -1106,8 +1146,12 @@ rhythmdb_query_model_update_limited_entr
 		ptr = g_sequence_ptr_prev (g_sequence_get_end_ptr (model->priv->entries));
 		entry = (RhythmDBEntry*) g_sequence_ptr_get_data (ptr);
 
+		/* take temporary ref */
+		rhythmdb_entry_ref (entry);
 		rhythmdb_query_model_remove_from_main_list (model, entry);
 		rhythmdb_query_model_insert_into_limited_list (model, entry);
+		/* release temporary ref */
+		rhythmdb_entry_unref (entry);
 	}
 
 	/* move entries that were previously limited, back to the main list */
@@ -1125,8 +1169,12 @@ rhythmdb_query_model_update_limited_entr
 		if (!rhythmdb_query_model_within_limit (model, entry))
 			break;
 
+		/* take temporary ref */
+		rhythmdb_entry_ref (entry);
 		rhythmdb_query_model_remove_from_limited_list (model, entry);
 		rhythmdb_query_model_insert_into_main_list (model, entry, -1);
+		/* release temporary ref */
+		rhythmdb_entry_unref (entry);
 
 		ptr = g_hash_table_lookup (model->priv->reverse_map, entry);
 		iter.stamp = model->priv->stamp;
@@ -1140,7 +1188,9 @@ rhythmdb_query_model_update_limited_entr
 }
 
 static gboolean
-rhythmdb_query_model_emit_reorder (RhythmDBQueryModel *model, gint old_pos, gint new_pos)
+rhythmdb_query_model_emit_reorder (RhythmDBQueryModel *model,
+				   gint old_pos,
+				   gint new_pos)
 {
 	int length, i;
 	gint *reorder_map;
@@ -1187,7 +1237,8 @@ rhythmdb_query_model_emit_reorder (Rhyth
 }
 
 static gboolean
-rhythmdb_query_model_do_reorder (RhythmDBQueryModel *model, RhythmDBEntry *entry)
+rhythmdb_query_model_do_reorder (RhythmDBQueryModel *model,
+				 RhythmDBEntry *entry)
 {
 	GSequencePtr ptr;
 	int old_pos, new_pos;
@@ -1218,8 +1269,12 @@ rhythmdb_query_model_do_reorder (RhythmD
 
 		if (cmp > 0) {
 			/* the entry belongs in the limited list, so we don't need a re-order */
+			/* take temporary ref */
+			rhythmdb_entry_ref (entry);
 			rhythmdb_query_model_remove_entry (model, entry);
 			rhythmdb_query_model_do_insert (model, entry, -1);
+			/* release temporary ref */
+			rhythmdb_entry_unref (entry);
 			return TRUE;
 		}
 	}
@@ -1233,6 +1288,9 @@ rhythmdb_query_model_do_reorder (RhythmD
 				     path, &iter);
 	gtk_tree_path_free (path);
 
+	/* take a temporary ref */
+	rhythmdb_entry_ref (entry);
+
 	/* it may have moved, check for a re-order */
 	g_hash_table_remove (model->priv->reverse_map, entry);
 	old_pos = g_sequence_ptr_get_position (ptr);
@@ -1242,6 +1300,8 @@ rhythmdb_query_model_do_reorder (RhythmD
 					sort_func,
 					sort_data);
 	new_pos = g_sequence_ptr_get_position (ptr);
+
+	/* the hash now owns this reference to the entry */
 	g_hash_table_insert (model->priv->reverse_map, entry, ptr);
 
 	return rhythmdb_query_model_emit_reorder (model, old_pos, new_pos);
@@ -1261,12 +1321,20 @@ rhythmdb_query_model_do_insert (RhythmDB
 	/* we check again if the entry already exists in the hash table */
 	if (g_hash_table_lookup (model->priv->reverse_map, entry) != NULL)
 		return;
+
+	/* take temporary ref */
+	rhythmdb_entry_ref (entry);
+
 	ptr = g_hash_table_lookup (model->priv->limited_reverse_map, entry);
-	if (ptr != NULL)
+	if (ptr != NULL) {
 		rhythmdb_query_model_remove_from_limited_list (model, entry);
+	}
 
 	rhythmdb_query_model_insert_into_main_list (model, entry, index);
 
+	/* release temporary ref */
+	rhythmdb_entry_unref (entry);
+
 	/* it was added to the main list, send out the inserted signal */
 	ptr = g_hash_table_lookup (model->priv->reverse_map, entry);
 	iter.stamp = model->priv->stamp;
@@ -1302,7 +1370,9 @@ rhythmdb_query_model_filter_out_entry (R
 }
 
 void
-rhythmdb_query_model_move_entry (RhythmDBQueryModel *model, RhythmDBEntry *entry, gint index)
+rhythmdb_query_model_move_entry (RhythmDBQueryModel *model,
+				 RhythmDBEntry *entry,
+				 gint index)
 {
 	GSequencePtr ptr;
 	GSequencePtr nptr;
@@ -1316,6 +1386,9 @@ rhythmdb_query_model_move_entry (RhythmD
 	if ((nptr == NULL) || (ptr == nptr))
 		return;
 
+	/* take temporary ref */
+	rhythmdb_entry_ref (entry);
+
 	/* remove from old position */
 	old_pos = g_sequence_ptr_get_position (ptr);
 	g_sequence_remove (ptr);
@@ -1324,6 +1397,8 @@ rhythmdb_query_model_move_entry (RhythmD
 	/* insert into new position */
 	g_sequence_insert (nptr, entry);
 	ptr = g_sequence_ptr_prev (nptr);
+
+	/* the hash now owns this reference to the entry */
 	g_hash_table_insert (model->priv->reverse_map, entry, ptr);
 
 	rhythmdb_query_model_emit_reorder (model, old_pos, index);
@@ -1337,7 +1412,7 @@ rhythmdb_query_model_remove_entry (Rhyth
 			    (g_hash_table_lookup (model->priv->limited_reverse_map, entry) == NULL);
 	g_return_val_if_fail (present, FALSE);
 
-	if (model->priv->base_model)
+	if (model->priv->base_model != NULL)
 		return rhythmdb_query_model_remove_entry (model->priv->base_model, entry);
 
 	/* emit entry-removed, so listeners know the
@@ -1353,7 +1428,8 @@ rhythmdb_query_model_remove_entry (Rhyth
 }
 
 gboolean
-rhythmdb_query_model_entry_to_iter (RhythmDBQueryModel *model, RhythmDBEntry *entry,
+rhythmdb_query_model_entry_to_iter (RhythmDBQueryModel *model,
+				    RhythmDBEntry *entry,
 				    GtkTreeIter *iter)
 {
 	GSequencePtr ptr;
@@ -1383,7 +1459,7 @@ rhythmdb_query_model_tree_path_to_entry 
 
 RhythmDBEntry *
 rhythmdb_query_model_iter_to_entry (RhythmDBQueryModel *model,
-				     GtkTreeIter *entry_iter)
+				    GtkTreeIter *entry_iter)
 {
 	RhythmDBEntry *entry;
 	gtk_tree_model_get (GTK_TREE_MODEL (model), entry_iter, 0, &entry, -1);
@@ -1431,18 +1507,20 @@ rhythmdb_query_model_get_previous_from_e
 
 	g_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path));
 	gtk_tree_path_free (path);
+
 	return rhythmdb_query_model_iter_to_entry (model, &iter);
 }
 
 static gboolean
 rhythmdb_query_model_row_draggable (RbTreeDragSource *dragsource,
-					  GList *paths)
+				    GList *paths)
 {
 	return TRUE;
 }
 
 static gboolean
-rhythmdb_query_model_drag_data_delete (RbTreeDragSource *dragsource, GList *paths)
+rhythmdb_query_model_drag_data_delete (RbTreeDragSource *dragsource,
+				       GList *paths)
 {
 	RhythmDBQueryModel *model = RHYTHMDB_QUERY_MODEL (dragsource);
 	GtkTreeModel *treemodel = GTK_TREE_MODEL (model);
@@ -1476,8 +1554,8 @@ rhythmdb_query_model_drag_data_delete (R
 
 static gboolean
 rhythmdb_query_model_drag_data_get (RbTreeDragSource *dragsource,
-					  GList *paths,
-					  GtkSelectionData *selection_data)
+				    GList *paths,
+				    GtkSelectionData *selection_data)
 {
 	RhythmDBQueryModel *model = RHYTHMDB_QUERY_MODEL (dragsource);
 	guint target;
@@ -1532,7 +1610,7 @@ static gboolean
 rhythmdb_query_model_drag_data_received (RbTreeDragDest *drag_dest,
 					 GtkTreePath *dest,
 					 GtkTreeViewDropPosition pos,
-					 GtkSelectionData  *selection_data)
+					 GtkSelectionData *selection_data)
 {
 	RhythmDBQueryModel *model = RHYTHMDB_QUERY_MODEL (drag_dest);
 
@@ -1547,6 +1625,7 @@ rhythmdb_query_model_drag_data_received 
 			g_assert (entry);
 			rhythmdb_query_model_entry_to_iter (model->priv->base_model, entry, &base_iter);
 			base_dest = gtk_tree_model_get_path (GTK_TREE_MODEL (model->priv->base_model), &base_iter);
+			rhythmdb_entry_unref (entry);
 		} else {
 			base_dest = NULL;
 		}
@@ -1612,6 +1691,8 @@ rhythmdb_query_model_drag_data_received 
 				/* trying to drag drop an entry on itself ! */
 				if (old_ptr == ptr)
 					continue;
+
+				/* take temporary ref */
 				rhythmdb_entry_ref (entry);
 
 				/* the entry already exists it is either a reorder drag and drop
@@ -1623,7 +1704,6 @@ rhythmdb_query_model_drag_data_received 
 					old_pos = g_sequence_ptr_get_position (old_ptr);
 					g_sequence_remove (old_ptr);
 					g_assert (g_hash_table_remove (model->priv->reverse_map, entry));
-					rhythmdb_entry_unref (entry);
 				} else {
 					model->priv->reorder_drag_and_drop = FALSE;
 				}
@@ -1635,6 +1715,7 @@ rhythmdb_query_model_drag_data_received 
 
 				tem_iter.stamp = model->priv->stamp;
 				tem_iter.user_data = tem_ptr;
+				/* the hash now owns this reference to the entry */
 				g_hash_table_insert (model->priv->reverse_map, entry, tem_ptr);
 
 				if (old_ptr) {
@@ -1660,7 +1741,7 @@ static gboolean
 rhythmdb_query_model_row_drop_possible (RbTreeDragDest *drag_dest,
 					GtkTreePath *dest,
 					GtkTreeViewDropPosition pos,
-					GtkSelectionData  *selection_data)
+					GtkSelectionData *selection_data)
 {
 	RhythmDBQueryModel *model = RHYTHMDB_QUERY_MODEL (drag_dest);
 
@@ -1674,8 +1755,8 @@ rhythmdb_query_model_row_drop_possible (
 }
 
 static gboolean
-rhythmdb_query_model_row_drop_position (RbTreeDragDest   *drag_dest,
-					GtkTreePath       *dest_path,
+rhythmdb_query_model_row_drop_position (RbTreeDragDest *drag_dest,
+					GtkTreePath *dest_path,
 					GList *targets,
 					GtkTreeViewDropPosition *pos)
 {
@@ -1692,7 +1773,8 @@ rhythmdb_query_model_set_query (RhythmDB
  *  from the main thread for synchronous queries.
  */
 static void
-rhythmdb_query_model_add_results (RhythmDBQueryResults *results, GPtrArray *entries)
+rhythmdb_query_model_add_results (RhythmDBQueryResults *results,
+				  GPtrArray *entries)
 {
 	RhythmDBQueryModel *model = RHYTHMDB_QUERY_MODEL (results);
 	struct RhythmDBQueryModelUpdate *update;
@@ -1704,10 +1786,13 @@ rhythmdb_query_model_add_results (Rhythm
 	update->type = RHYTHMDB_QUERY_MODEL_UPDATE_ROWS_INSERTED;
 	update->entrydata.entries = entries;
 	update->model = model;
-	g_object_ref (G_OBJECT (model));
 
-	for (i = 0; i < update->entrydata.entries->len; i++)
+	/* take references; released in update idle */
+	g_object_ref (model);
+
+	for (i = 0; i < update->entrydata.entries->len; i++) {
 		rhythmdb_entry_ref (g_ptr_array_index (update->entrydata.entries, i));
+	}
 
 	rhythmdb_query_model_process_update (update);
 }
@@ -1721,7 +1806,9 @@ rhythmdb_query_model_query_complete (Rhy
 	update = g_new0 (struct RhythmDBQueryModelUpdate, 1);
 	update->type = RHYTHMDB_QUERY_MODEL_UPDATE_QUERY_COMPLETE;
 	update->model = model;
-	g_object_ref (G_OBJECT (model));
+
+	/* take reference; released in update idle */
+	g_object_ref (model);
 
 	rhythmdb_query_model_process_update (update);
 }
@@ -1739,10 +1826,10 @@ rhythmdb_query_model_get_n_columns (GtkT
 }
 
 static GType
-rhythmdb_query_model_get_column_type (GtkTreeModel *tree_model, int index)
+rhythmdb_query_model_get_column_type (GtkTreeModel *tree_model,
+				      int index)
 {
-	switch (index)
-	{
+	switch (index) {
 	case 0:
 		return RHYTHMDB_TYPE_ENTRY;
 	case 1:
@@ -1754,7 +1841,8 @@ rhythmdb_query_model_get_column_type (Gt
 }
 
 static gboolean
-rhythmdb_query_model_get_iter (GtkTreeModel *tree_model, GtkTreeIter *iter,
+rhythmdb_query_model_get_iter (GtkTreeModel *tree_model,
+			       GtkTreeIter *iter,
 			       GtkTreePath *path)
 {
 	RhythmDBQueryModel *model = RHYTHMDB_QUERY_MODEL (tree_model);
@@ -1793,8 +1881,10 @@ rhythmdb_query_model_get_path (GtkTreeMo
 }
 
 static void
-rhythmdb_query_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter,
-				gint column, GValue *value)
+rhythmdb_query_model_get_value (GtkTreeModel *tree_model,
+				GtkTreeIter *iter,
+				gint column,
+				GValue *value)
 {
 	RhythmDBQueryModel *model = RHYTHMDB_QUERY_MODEL (tree_model);
 	RhythmDBEntry *entry;
@@ -1804,8 +1894,7 @@ rhythmdb_query_model_get_value (GtkTreeM
 
 	entry = g_sequence_ptr_get_data (iter->user_data);
 
-	switch (column)
-	{
+	switch (column) {
 	case 0:
 		g_value_init (value, RHYTHMDB_TYPE_ENTRY);
 		g_value_set_boxed (value, entry);
@@ -1874,7 +1963,8 @@ rhythmdb_query_model_iter_n_children (Gt
 
 static gboolean
 rhythmdb_query_model_iter_nth_child (GtkTreeModel *tree_model,
-				     GtkTreeIter *iter, GtkTreeIter *parent,
+				     GtkTreeIter *iter,
+				     GtkTreeIter *parent,
 				     gint n)
 {
 	RhythmDBQueryModel *model = RHYTHMDB_QUERY_MODEL (tree_model);
@@ -1915,7 +2005,8 @@ rhythmdb_query_model_compute_status_norm
 }
 
 static void
-apply_updated_entry_sequence (RhythmDBQueryModel *model, GSequence *new_entries)
+apply_updated_entry_sequence (RhythmDBQueryModel *model,
+			      GSequence *new_entries)
 {
 	int *reorder_map;
 	int length, i;
@@ -2009,7 +2100,8 @@ rhythmdb_query_model_set_sort_order (Rhy
 }
 
 static int
-rhythmdb_query_model_child_index_to_base_index (RhythmDBQueryModel *model, int index)
+rhythmdb_query_model_child_index_to_base_index (RhythmDBQueryModel *model,
+						int index)
 {
 	GSequencePtr ptr;
 	RhythmDBEntry *entry;
@@ -2051,7 +2143,8 @@ rhythmdb_query_model_base_index_to_child
 }*/
 
 static int
-rhythmdb_query_model_get_entry_index (RhythmDBQueryModel *model, RhythmDBEntry *entry)
+rhythmdb_query_model_get_entry_index (RhythmDBQueryModel *model,
+				      RhythmDBEntry *entry)
 {
 	GSequencePtr ptr = g_hash_table_lookup (model->priv->reverse_map, entry);
 
@@ -2075,24 +2168,33 @@ rhythmdb_query_model_base_row_inserted (
 	g_assert (base_model == model->priv->base_model);
 
 	entry = rhythmdb_query_model_iter_to_entry (base_model, iter);
+
 	if (!model->priv->show_hidden && rhythmdb_entry_get_boolean (entry, RHYTHMDB_PROP_HIDDEN))
-		return;
+		goto out;
 
 	if (rhythmdb_evaluate_query (model->priv->db, model->priv->query, entry)) {
 		/* find the closest previous entry that is in the filter model, and it it after that */
 		prev_entry = rhythmdb_query_model_get_previous_from_entry (base_model, entry);
 		while (prev_entry && g_hash_table_lookup (model->priv->reverse_map, prev_entry) == NULL) {
+			rhythmdb_entry_unref (prev_entry);
 			prev_entry = rhythmdb_query_model_get_previous_from_entry (base_model, prev_entry);
 		}
 
-		if (entry != NULL)
+		if (entry != NULL) {
 			index = rhythmdb_query_model_get_entry_index (model, prev_entry) + 1;
-		else
+		} else {
 			index = 0;
+		}
+
+		if (prev_entry != NULL) {
+			rhythmdb_entry_unref (prev_entry);
+		}
 
 		rb_debug ("inserting entry %p from base model %p to model %p in position %d", entry, base_model, model, index);
 		rhythmdb_query_model_do_insert (model, entry, index);
 	}
+ out:
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -2106,6 +2208,7 @@ rhythmdb_query_model_base_row_deleted (G
 	rb_debug ("deleting entry %p from base model %p to model %p", entry, base_model, model);
 
 	rhythmdb_query_model_filter_out_entry (model, entry);
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -2168,7 +2271,8 @@ rhythmdb_query_model_base_entry_removed 
 }
 
 void
-rhythmdb_query_model_reapply_query (RhythmDBQueryModel *model, gboolean filter)
+rhythmdb_query_model_reapply_query (RhythmDBQueryModel *model,
+				    gboolean filter)
 {
 	GSequencePtr ptr;
 	GSequencePtr next;
@@ -2243,14 +2347,16 @@ rhythmdb_query_model_reapply_query (Rhyt
 }
 
 static gint
-_reverse_sorting_func (gpointer a, gpointer b,
+_reverse_sorting_func (gpointer a,
+		       gpointer b,
 		       struct ReverseSortData *reverse_data)
 {
 	return - reverse_data->func (a, b, reverse_data->data);
 }
 
 gint
-rhythmdb_query_model_location_sort_func (RhythmDBEntry *a, RhythmDBEntry *b,
+rhythmdb_query_model_location_sort_func (RhythmDBEntry *a,
+					 RhythmDBEntry *b,
 					 gpointer data)
 {
 	const char *a_val;
@@ -2271,7 +2377,8 @@ rhythmdb_query_model_location_sort_func 
 }
 
 gint
-rhythmdb_query_model_title_sort_func (RhythmDBEntry *a, RhythmDBEntry *b,
+rhythmdb_query_model_title_sort_func (RhythmDBEntry *a,
+				      RhythmDBEntry *b,
 				      gpointer data)
 {
 	const char *a_val;
@@ -2299,7 +2406,8 @@ rhythmdb_query_model_title_sort_func (Rh
 }
 
 gint
-rhythmdb_query_model_album_sort_func (RhythmDBEntry *a, RhythmDBEntry *b,
+rhythmdb_query_model_album_sort_func (RhythmDBEntry *a,
+				      RhythmDBEntry *b,
 				      gpointer data)
 {
 	const char *a_val;
@@ -2353,7 +2461,8 @@ rhythmdb_query_model_album_sort_func (Rh
 }
 
 gint
-rhythmdb_query_model_artist_sort_func (RhythmDBEntry *a, RhythmDBEntry *b,
+rhythmdb_query_model_artist_sort_func (RhythmDBEntry *a,
+				       RhythmDBEntry *b,
 				       gpointer data)
 {
 	const char *a_val;
@@ -2407,14 +2516,16 @@ rhythmdb_query_model_genre_sort_func (Rh
 }
 
 gint
-rhythmdb_query_model_track_sort_func (RhythmDBEntry *a, RhythmDBEntry *b,
+rhythmdb_query_model_track_sort_func (RhythmDBEntry *a,
+				      RhythmDBEntry *b,
 				      gpointer data)
 {
 	return rhythmdb_query_model_album_sort_func (a, b, data);
 }
 
 gint
-rhythmdb_query_model_double_ceiling_sort_func (RhythmDBEntry *a, RhythmDBEntry *b,
+rhythmdb_query_model_double_ceiling_sort_func (RhythmDBEntry *a,
+					       RhythmDBEntry *b,
 					       gpointer data)
 {
 	gdouble a_val, b_val;
@@ -2432,7 +2543,8 @@ rhythmdb_query_model_double_ceiling_sort
 }
 
 gint
-rhythmdb_query_model_ulong_sort_func (RhythmDBEntry *a, RhythmDBEntry *b,
+rhythmdb_query_model_ulong_sort_func (RhythmDBEntry *a,
+				      RhythmDBEntry *b,
 				      gpointer data)
 {
 	gulong a_val, b_val;
@@ -2449,7 +2561,8 @@ rhythmdb_query_model_ulong_sort_func (Rh
 }
 
 gint
-rhythmdb_query_model_date_sort_func (RhythmDBEntry *a, RhythmDBEntry *b,
+rhythmdb_query_model_date_sort_func (RhythmDBEntry *a,
+				     RhythmDBEntry *b,
 				     gpointer data)
 
 {
@@ -2469,7 +2582,8 @@ rhythmdb_query_model_date_sort_func (Rhy
 }
 
 gint
-rhythmdb_query_model_string_sort_func (RhythmDBEntry *a, RhythmDBEntry *b,
+rhythmdb_query_model_string_sort_func (RhythmDBEntry *a,
+				       RhythmDBEntry *b,
 				       gpointer data)
 {
 	const char *a_val;
@@ -2498,7 +2612,8 @@ rhythmdb_query_model_string_sort_func (R
 }
 
 static gboolean
-rhythmdb_query_model_within_limit (RhythmDBQueryModel *model, RhythmDBEntry *entry)
+rhythmdb_query_model_within_limit (RhythmDBQueryModel *model,
+				   RhythmDBEntry *entry)
 {
 	gboolean result = TRUE;
 
Index: rhythmdb/rhythmdb-tree.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/rhythmdb/rhythmdb-tree.c,v
retrieving revision 1.114
diff -p -u -r1.114 rhythmdb-tree.c
--- rhythmdb/rhythmdb-tree.c	17 Jul 2006 14:52:12 -0000	1.114
+++ rhythmdb/rhythmdb-tree.c	21 Jul 2006 21:31:31 -0000
@@ -20,7 +20,8 @@
  *
  */
 
-#include <config.h>
+#include "config.h"
+
 #ifdef HAVE_GNU_FWRITE_UNLOCKED
 #define _GNU_SOURCE
 #endif
@@ -181,7 +182,9 @@ rhythmdb_tree_init (RhythmDBTree *db)
 }
 
 static void
-unparent_entries (const char *uri, RhythmDBEntry *entry, RhythmDBTree *db)
+unparent_entries (const char *uri,
+		  RhythmDBEntry *entry,
+		  RhythmDBTree *db)
 {
 	remove_entry_from_album (db, entry);
 }
@@ -269,7 +272,8 @@ struct RhythmDBTreeLoadContext
 
 static void
 rhythmdb_tree_parser_start_element (struct RhythmDBTreeLoadContext *ctx,
-				    const char *name, const char **attrs)
+				    const char *name,
+				    const char **attrs)
 {
 	if (*ctx->die == TRUE) {
 		xmlStopParser (ctx->xmlctx);
@@ -378,7 +382,8 @@ rhythmdb_tree_parser_start_element (stru
 }
 
 static void
-rhythmdb_tree_parser_end_element (struct RhythmDBTreeLoadContext *ctx, const char *name)
+rhythmdb_tree_parser_end_element (struct RhythmDBTreeLoadContext *ctx,
+				  const char *name)
 {
 	if (*ctx->die == TRUE) {
 		xmlStopParser (ctx->xmlctx);
@@ -531,7 +536,8 @@ rhythmdb_tree_parser_end_element (struct
 }
 
 static void
-rhythmdb_tree_parser_characters (struct RhythmDBTreeLoadContext *ctx, const char *data,
+rhythmdb_tree_parser_characters (struct RhythmDBTreeLoadContext *ctx,
+				 const char *data,
 				 guint len)
 {
 	if (*ctx->die == TRUE) {
@@ -555,14 +561,18 @@ rhythmdb_tree_parser_characters (struct 
 }
 
 static void
-rhythmdb_tree_load (RhythmDB *rdb, gboolean *die)
+rhythmdb_tree_load (RhythmDB *rdb,
+		    gboolean *die)
 {
 	RhythmDBTree *db = RHYTHMDB_TREE (rdb);
 	xmlParserCtxtPtr ctxt;
-	xmlSAXHandlerPtr sax_handler = g_new0 (xmlSAXHandler, 1);
-	struct RhythmDBTreeLoadContext *ctx = g_new0 (struct RhythmDBTreeLoadContext, 1);
+	xmlSAXHandlerPtr sax_handler;
+	struct RhythmDBTreeLoadContext *ctx;
 	char *name;
 
+	sax_handler = g_new0 (xmlSAXHandler, 1);
+	ctx = g_new0 (struct RhythmDBTreeLoadContext, 1);
+
 	sax_handler->startElement = (startElementSAXFunc) rhythmdb_tree_parser_start_element;
 	sax_handler->endElement = (endElementSAXFunc) rhythmdb_tree_parser_end_element;
 	sax_handler->characters = (charactersSAXFunc) rhythmdb_tree_parser_characters;
@@ -588,6 +598,7 @@ rhythmdb_tree_load (RhythmDB *rdb, gbool
 			rhythmdb_commit (RHYTHMDB (ctx->db));
 
 	}
+
 	g_string_free (ctx->buf, TRUE);
 	g_free (name);
 	g_free (sax_handler);
@@ -628,7 +639,8 @@ struct RhythmDBTreeSaveContext
 #define RHYTHMDB_FWRITE_STATICSTR(STR, HANDLE, ERROR) RHYTHMDB_FWRITE(STR, 1, sizeof(STR)-1, HANDLE, ERROR)
 
 static void
-write_elt_name_open (struct RhythmDBTreeSaveContext *ctx, const xmlChar *elt_name)
+write_elt_name_open (struct RhythmDBTreeSaveContext *ctx,
+		     const xmlChar *elt_name)
 {
 	RHYTHMDB_FWRITE_STATICSTR ("    <", ctx->handle, ctx->error);
 	RHYTHMDB_FWRITE (elt_name, 1, xmlStrlen (elt_name), ctx->handle, ctx->error);
@@ -636,7 +648,8 @@ write_elt_name_open (struct RhythmDBTree
 }
 
 static void
-write_elt_name_close (struct RhythmDBTreeSaveContext *ctx, const xmlChar *elt_name)
+write_elt_name_close (struct RhythmDBTreeSaveContext *ctx,
+		      const xmlChar *elt_name)
 {
 	RHYTHMDB_FWRITE_STATICSTR ("</", ctx->handle, ctx->error);
 	RHYTHMDB_FWRITE (elt_name, 1, xmlStrlen (elt_name), ctx->handle, ctx->error);
@@ -645,7 +658,8 @@ write_elt_name_close (struct RhythmDBTre
 
 static void
 save_entry_string (struct RhythmDBTreeSaveContext *ctx,
-		   const xmlChar *elt_name, const char *str)
+		   const xmlChar *elt_name,
+		   const char *str)
 {
 	xmlChar *encoded;
 
@@ -659,7 +673,8 @@ save_entry_string (struct RhythmDBTreeSa
 
 static void
 save_entry_int (struct RhythmDBTreeSaveContext *ctx,
-		const xmlChar *elt_name, int num)
+		const xmlChar *elt_name,
+		int num)
 {
 	char buf[92];
 	if (num == 0)
@@ -672,9 +687,12 @@ save_entry_int (struct RhythmDBTreeSaveC
 
 static void
 save_entry_ulong (struct RhythmDBTreeSaveContext *ctx,
-		  const xmlChar *elt_name, gulong num, gboolean save_zeroes)
+		  const xmlChar *elt_name,
+		  gulong num,
+		  gboolean save_zeroes)
 {
 	char buf[92];
+
 	if (num == 0 && !save_zeroes)
 		return;
 	write_elt_name_open (ctx, elt_name);
@@ -685,13 +703,15 @@ save_entry_ulong (struct RhythmDBTreeSav
 
 static void
 save_entry_boolean (struct RhythmDBTreeSaveContext *ctx,
-		    const xmlChar *elt_name, gboolean val)
+		    const xmlChar *elt_name,
+		    gboolean val)
 {
 	save_entry_ulong (ctx, elt_name, val ? 1 : 0, FALSE);
 }
 
 static void
-save_entry_uint64 (struct RhythmDBTreeSaveContext *ctx, const xmlChar *elt_name,
+save_entry_uint64 (struct RhythmDBTreeSaveContext *ctx,
+		   const xmlChar *elt_name,
 		   guint64 num)
 {
 	char buf[92];
@@ -707,7 +727,8 @@ save_entry_uint64 (struct RhythmDBTreeSa
 
 static void
 save_entry_double (struct RhythmDBTreeSaveContext *ctx,
-		   const xmlChar *elt_name, double num)
+		   const xmlChar *elt_name,
+		   double num)
 {
 	char buf[92];
 
@@ -724,7 +745,9 @@ save_entry_double (struct RhythmDBTreeSa
  * readability cost.  Sorry about that.
  */
 static void
-save_entry (RhythmDBTree *db, RhythmDBEntry *entry, struct RhythmDBTreeSaveContext *ctx)
+save_entry (RhythmDBTree *db,
+	    RhythmDBEntry *entry,
+	    struct RhythmDBTreeSaveContext *ctx)
 {
 	RhythmDBPropType i;
 	RhythmDBPodcastFields *podcast = NULL;
@@ -753,8 +776,7 @@ save_entry (RhythmDBTree *db, RhythmDBEn
 
 		elt_name = rhythmdb_nice_elt_name_from_propid ((RhythmDB *) ctx->db, i);
 
-		switch (i)
-		{
+		switch (i) {
 		case RHYTHMDB_PROP_TYPE:
 			break;
 		case RHYTHMDB_PROP_TITLE:
@@ -1022,7 +1044,9 @@ rhythmdb_tree_new (const char *name)
 }
 
 static void
-set_entry_album (RhythmDBTree *db, RhythmDBEntry *entry, RhythmDBTreeProperty *artist,
+set_entry_album (RhythmDBTree *db,
+		 RhythmDBEntry *entry,
+		 RhythmDBTreeProperty *artist,
 		 RBRefString *name)
 {
 	struct RhythmDBTreeProperty *prop;
@@ -1032,7 +1056,8 @@ set_entry_album (RhythmDBTree *db, Rhyth
 }
 
 static void
-rhythmdb_tree_entry_new (RhythmDB *rdb, RhythmDBEntry *entry)
+rhythmdb_tree_entry_new (RhythmDB *rdb,
+			 RhythmDBEntry *entry)
 {
 	RhythmDBTree *db = RHYTHMDB_TREE (rdb);
 	RhythmDBTreeProperty *artist;
@@ -1085,7 +1110,8 @@ rhythmdb_tree_property_new (RhythmDBTree
 }
 
 static GHashTable *
-get_genres_hash_for_type (RhythmDBTree *db, RhythmDBEntryType type)
+get_genres_hash_for_type (RhythmDBTree *db,
+			  RhythmDBEntryType type)
 {
 	GHashTable *table;
 
@@ -1135,7 +1161,8 @@ genres_hash_foreach (RhythmDBTree *db, R
 }
 
 static RhythmDBTreeProperty *
-get_or_create_genre (RhythmDBTree *db, RhythmDBEntryType type,
+get_or_create_genre (RhythmDBTree *db,
+		     RhythmDBEntryType type,
 		     RBRefString *name)
 {
 	RhythmDBTreeProperty *genre;
@@ -1158,7 +1185,8 @@ get_or_create_genre (RhythmDBTree *db, R
 }
 
 static RhythmDBTreeProperty *
-get_or_create_artist (RhythmDBTree *db, RhythmDBTreeProperty *genre,
+get_or_create_artist (RhythmDBTree *db,
+		      RhythmDBTreeProperty *genre,
 		      RBRefString *name)
 {
 	RhythmDBTreeProperty *artist;
@@ -1179,7 +1207,8 @@ get_or_create_artist (RhythmDBTree *db, 
 }
 
 static RhythmDBTreeProperty *
-get_or_create_album (RhythmDBTree *db, RhythmDBTreeProperty *artist,
+get_or_create_album (RhythmDBTree *db,
+		     RhythmDBTreeProperty *artist,
 		     RBRefString *name)
 {
 	RhythmDBTreeProperty *album;
@@ -1198,7 +1227,8 @@ get_or_create_album (RhythmDBTree *db, R
 }
 
 static gboolean
-remove_child (RhythmDBTreeProperty *parent, gconstpointer data)
+remove_child (RhythmDBTreeProperty *parent,
+	      gconstpointer data)
 {
 	g_assert (g_hash_table_remove (parent->children, data));
 	if (g_hash_table_size (parent->children) <= 0) {
@@ -1208,7 +1238,8 @@ remove_child (RhythmDBTreeProperty *pare
 }
 
 static void
-remove_entry_from_album (RhythmDBTree *db, RhythmDBEntry *entry)
+remove_entry_from_album (RhythmDBTree *db,
+			 RhythmDBEntry *entry)
 {
 	GHashTable *table;
 
@@ -1238,8 +1269,10 @@ remove_entry_from_album (RhythmDBTree *d
 }
 
 static gboolean
-rhythmdb_tree_entry_set (RhythmDB *adb, RhythmDBEntry *entry,
-			 guint propid, const GValue *value)
+rhythmdb_tree_entry_set (RhythmDB *adb,
+			 RhythmDBEntry *entry,
+			 guint propid,
+			 const GValue *value)
 {
 	RhythmDBTree *db = RHYTHMDB_TREE (adb);
 	RhythmDBEntryType type;
@@ -1354,7 +1387,8 @@ rhythmdb_tree_entry_set (RhythmDB *adb, 
 }
 
 static void
-rhythmdb_tree_entry_delete (RhythmDB *adb, RhythmDBEntry *entry)
+rhythmdb_tree_entry_delete (RhythmDB *adb,
+			    RhythmDBEntry *entry)
 {
 	RhythmDBTree *db = RHYTHMDB_TREE (adb);
 
@@ -1372,7 +1406,8 @@ typedef struct {
 } RbEntryRemovalCtxt;
 
 static gboolean
-remove_one_song (gchar *uri, RhythmDBEntry *entry,
+remove_one_song (gchar *uri,
+		 RhythmDBEntry *entry,
 		 RbEntryRemovalCtxt *ctxt)
 {
 	g_return_val_if_fail (entry != NULL, FALSE);
@@ -1387,7 +1422,8 @@ remove_one_song (gchar *uri, RhythmDBEnt
 }
 
 static void
-rhythmdb_tree_entry_delete_by_type (RhythmDB *adb, RhythmDBEntryType type)
+rhythmdb_tree_entry_delete_by_type (RhythmDB *adb,
+				    RhythmDBEntryType type)
 {
 	RhythmDBTree *db = RHYTHMDB_TREE (adb);
 	RbEntryRemovalCtxt ctxt;
@@ -1421,7 +1457,8 @@ struct RhythmDBTreeTraversalData
 };
 
 static gboolean
-rhythmdb_tree_evaluate_query (RhythmDB *adb, GPtrArray *query,
+rhythmdb_tree_evaluate_query (RhythmDB *adb,
+			      GPtrArray *query,
 			      RhythmDBEntry *entry)
 {
 	RhythmDBTree *db = RHYTHMDB_TREE (adb);
@@ -1481,7 +1518,9 @@ rhythmdb_tree_evaluate_query (RhythmDB *
 			}
 
 static gboolean
-search_match_properties (RhythmDB *db, RhythmDBEntry *entry, gchar **words)
+search_match_properties (RhythmDB *db,
+			 RhythmDBEntry *entry,
+			 gchar **words)
 {
 	const RhythmDBPropType props[] = {
 		RHYTHMDB_PROP_TITLE_FOLDED,
@@ -1515,8 +1554,11 @@ search_match_properties (RhythmDB *db, R
 }
 
 static gboolean
-evaluate_conjunctive_subquery (RhythmDBTree *dbtree, GPtrArray *query,
-			       guint base, guint max, RhythmDBEntry *entry)
+evaluate_conjunctive_subquery (RhythmDBTree *dbtree,
+			       GPtrArray *query,
+			       guint base,
+			       guint max,
+			       RhythmDBEntry *entry)
 
 {
 	RhythmDB *db = (RhythmDB *) dbtree;
@@ -1641,7 +1683,8 @@ evaluate_conjunctive_subquery (RhythmDBT
 }
 
 static void
-do_conjunction (RhythmDBEntry *entry, gpointer unused,
+do_conjunction (RhythmDBEntry *entry,
+		gpointer unused,
 		struct RhythmDBTreeTraversalData *data)
 {
 	if (G_UNLIKELY (*data->cancel))
@@ -1654,7 +1697,8 @@ do_conjunction (RhythmDBEntry *entry, gp
 }
 
 static void
-conjunctive_query_songs (const char *name, RhythmDBTreeProperty *album,
+conjunctive_query_songs (const char *name,
+			 RhythmDBTreeProperty *album,
 			 struct RhythmDBTreeTraversalData *data)
 {
 	if (G_UNLIKELY (*data->cancel))
@@ -1663,7 +1707,8 @@ conjunctive_query_songs (const char *nam
 }
 
 static GPtrArray *
-clone_remove_ptr_array_index (GPtrArray *arr, guint index)
+clone_remove_ptr_array_index (GPtrArray *arr,
+			      guint index)
 {
 	GPtrArray *ret = g_ptr_array_new ();
 	guint i;
@@ -1675,7 +1720,8 @@ clone_remove_ptr_array_index (GPtrArray 
 }
 
 static void
-conjunctive_query_albums (const char *name, RhythmDBTreeProperty *artist,
+conjunctive_query_albums (const char *name,
+			  RhythmDBTreeProperty *artist,
 			  struct RhythmDBTreeTraversalData *data)
 {
 	guint i;
@@ -1717,7 +1763,8 @@ conjunctive_query_albums (const char *na
 }
 
 static void
-conjunctive_query_artists (const char *name, RhythmDBTreeProperty *genre,
+conjunctive_query_artists (const char *name,
+			   RhythmDBTreeProperty *genre,
 			   struct RhythmDBTreeTraversalData *data)
 {
 	guint i;
@@ -1758,7 +1805,8 @@ conjunctive_query_artists (const char *n
 }
 
 static void
-conjunctive_query_genre (RhythmDBTree *db, GHashTable *genres,
+conjunctive_query_genre (RhythmDBTree *db,
+			 GHashTable *genres,
 			 struct RhythmDBTreeTraversalData *data)
 {
 	int genre_query_idx = -1;
@@ -1802,8 +1850,10 @@ conjunctive_query_genre (RhythmDBTree *d
 }
 
 static void
-conjunctive_query (RhythmDBTree *db, GPtrArray *query,
-		   RhythmDBTreeTraversalFunc func, gpointer data,
+conjunctive_query (RhythmDBTree *db,
+		   GPtrArray *query,
+		   RhythmDBTreeTraversalFunc func,
+		   gpointer data,
 		   gboolean *cancel)
 {
 	int type_query_idx = -1;
@@ -1853,7 +1903,8 @@ conjunctive_query (RhythmDBTree *db, GPt
 }
 
 static GList *
-split_query_by_disjunctions (RhythmDBTree *db, GPtrArray *query)
+split_query_by_disjunctions (RhythmDBTree *db,
+			     GPtrArray *query)
 {
 	GList *conjunctions = NULL;
 	guint i, j;
@@ -1898,8 +1949,11 @@ struct RhythmDBTreeQueryGatheringData
 };
 
 static void
-do_query_recurse (RhythmDBTree *db, GPtrArray *query, RhythmDBTreeTraversalFunc func,
-		  struct RhythmDBTreeQueryGatheringData *data, gboolean *cancel)
+do_query_recurse (RhythmDBTree *db,
+		  GPtrArray *query,
+		  RhythmDBTreeTraversalFunc func,
+		  struct RhythmDBTreeQueryGatheringData *data,
+		  gboolean *cancel)
 {
 	GList *conjunctions, *tem;
 
@@ -1932,7 +1986,8 @@ do_query_recurse (RhythmDBTree *db, GPtr
 }
 
 static void
-handle_entry_match (RhythmDB *db, RhythmDBEntry *entry,
+handle_entry_match (RhythmDB *db,
+		    RhythmDBEntry *entry,
 		    struct RhythmDBTreeQueryGatheringData *data)
 {
 
@@ -1967,7 +2022,8 @@ rhythmdb_tree_do_full_query (RhythmDB *a
 }
 
 static RhythmDBEntry *
-rhythmdb_tree_entry_lookup_by_location (RhythmDB *adb, const char *uri)
+rhythmdb_tree_entry_lookup_by_location (RhythmDB *adb,
+					const char *uri)
 {
 	RhythmDBTree *db = RHYTHMDB_TREE (adb);
 	return g_hash_table_lookup (db->priv->entries, uri);
@@ -1981,14 +2037,18 @@ struct RhythmDBEntryForeachCtxt
 };
 
 static void
-rhythmdb_tree_entry_foreach_func (gpointer key, gpointer val, gpointer data)
+rhythmdb_tree_entry_foreach_func (gpointer key,
+				  gpointer val,
+				  gpointer data)
 {
 	struct RhythmDBEntryForeachCtxt * ctx = data;
 	ctx->func (val, ctx->user_data);
 }
 
 static void
-rhythmdb_tree_entry_foreach (RhythmDB *adb, GFunc func, gpointer user_data)
+rhythmdb_tree_entry_foreach (RhythmDB *adb,
+			     GFunc func,
+			     gpointer user_data)
 {
 	RhythmDBTree *db = RHYTHMDB_TREE (adb);
 	struct RhythmDBEntryForeachCtxt *ctx = g_new0 (struct RhythmDBEntryForeachCtxt, 1);
@@ -2010,7 +2070,9 @@ struct HashTreeIteratorCtxt {
 };
 
 static void
-hash_tree_entries_foreach (gpointer key, gpointer value, gpointer data)
+hash_tree_entries_foreach (gpointer key,
+			   gpointer value,
+			   gpointer data)
 {
 	RhythmDBEntry *entry = (RhythmDBEntry *) key;
 	struct HashTreeIteratorCtxt *ctxt = (struct HashTreeIteratorCtxt*)data;
@@ -2021,7 +2083,9 @@ hash_tree_entries_foreach (gpointer key,
 }
 
 static void
-hash_tree_albums_foreach (gpointer key, gpointer value, gpointer data)
+hash_tree_albums_foreach (gpointer key,
+			  gpointer value,
+			  gpointer data)
 {
 	RhythmDBTreeProperty *album = (RhythmDBTreeProperty *)value;
 	struct HashTreeIteratorCtxt *ctxt = (struct HashTreeIteratorCtxt*)data;
@@ -2037,7 +2101,9 @@ hash_tree_albums_foreach (gpointer key, 
 }
 
 static void
-hash_tree_artists_foreach (gpointer key, gpointer value, gpointer data)
+hash_tree_artists_foreach (gpointer key,
+			   gpointer value,
+			   gpointer data)
 {
 	RhythmDBTreeProperty *artist = (RhythmDBTreeProperty *)value;
 	struct HashTreeIteratorCtxt *ctxt = (struct HashTreeIteratorCtxt*)data;
@@ -2053,7 +2119,9 @@ hash_tree_artists_foreach (gpointer key,
 }
 
 static void
-hash_tree_genres_foreach (gpointer key, gpointer value, gpointer data)
+hash_tree_genres_foreach (gpointer key,
+			  gpointer value,
+			  gpointer data)
 {
 	RhythmDBTreeProperty *genre = (RhythmDBTreeProperty *)value;
 	struct HashTreeIteratorCtxt *ctxt = (struct HashTreeIteratorCtxt*)data;
Index: rhythmdb/rhythmdb.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/rhythmdb/rhythmdb.c,v
retrieving revision 1.240
diff -p -u -r1.240 rhythmdb.c
--- rhythmdb/rhythmdb.c	19 Jul 2006 11:18:03 -0000	1.240
+++ rhythmdb/rhythmdb.c	21 Jul 2006 21:31:31 -0000
@@ -245,7 +245,8 @@ rhythmdb_class_init (RhythmDBClass *klas
 }
 
 static gboolean
-metadata_field_from_prop (RhythmDBPropType prop, RBMetaDataField *field)
+metadata_field_from_prop (RhythmDBPropType prop,
+			  RBMetaDataField *field)
 {
 	switch (prop) {
 	case RHYTHMDB_PROP_TITLE:
@@ -290,7 +291,9 @@ metadata_field_from_prop (RhythmDBPropTy
 }
 
 static GType
-extract_gtype_from_enum_entry (RhythmDB *db, GEnumClass *klass, guint i)
+extract_gtype_from_enum_entry (RhythmDB *db,
+			       GEnumClass *klass,
+			       guint i)
 {
 	GType ret;
 	GEnumValue *value;
@@ -319,7 +322,9 @@ extract_gtype_from_enum_entry (RhythmDB 
 }
 
 static xmlChar *
-extract_nice_name_from_enum_entry (RhythmDB *db, GEnumClass *klass, guint i)
+extract_nice_name_from_enum_entry (RhythmDB *db,
+				   GEnumClass *klass,
+				   guint i)
 {
 	GEnumValue *value;
 	xmlChar *nick;
@@ -334,7 +339,7 @@ extract_nice_name_from_enum_entry (Rhyth
 	name_end = xmlStrstr (name, RB_PARSE_NICK_END);
 	name++;
 
-	return xmlStrndup (name, name_end-name);
+	return xmlStrndup (name, name_end - name);
 }
 
 static void
@@ -358,13 +363,14 @@ rhythmdb_init (RhythmDB *db)
 	prop_class = g_type_class_ref (RHYTHMDB_TYPE_PROP_TYPE);
 
 	g_assert (prop_class->n_values == RHYTHMDB_NUM_PROPERTIES);
-	db->priv->column_xml_names = g_new (xmlChar *, RHYTHMDB_NUM_PROPERTIES);
+	db->priv->column_xml_names = g_new0 (xmlChar *, RHYTHMDB_NUM_PROPERTIES);
 
 	/* Now, extract the GType and XML tag of each column from the
 	 * enum descriptions, and cache that for later use. */
 	for (i = 0; i < prop_class->n_values; i++) {
 		rhythmdb_property_type_map[i] = extract_gtype_from_enum_entry (db, prop_class, i);
 		g_assert (rhythmdb_property_type_map[i] != G_TYPE_INVALID);
+
 		db->priv->column_xml_names[i] = extract_nice_name_from_enum_entry (db, prop_class, i);
 		g_assert (db->priv->column_xml_names[i]);
 	}
@@ -383,15 +389,26 @@ rhythmdb_init (RhythmDB *db)
 	db->priv->entry_type_mutex = g_mutex_new ();
 	rhythmdb_register_core_entry_types (db);
 
- 	db->priv->stat_events = g_hash_table_new_full (gnome_vfs_uri_hash, (GEqualFunc) gnome_vfs_uri_equal,
+ 	db->priv->stat_events = g_hash_table_new_full (gnome_vfs_uri_hash,
+						       (GEqualFunc) gnome_vfs_uri_equal,
  						       (GDestroyNotify) gnome_vfs_uri_unref,
  						       NULL);
  	db->priv->stat_mutex = g_mutex_new ();
 
 	db->priv->change_mutex = g_mutex_new ();
-	db->priv->changed_entries = g_hash_table_new (NULL, NULL);
-	db->priv->added_entries = g_hash_table_new (NULL, NULL);
-	db->priv->deleted_entries = g_hash_table_new (NULL, NULL);
+
+	db->priv->changed_entries = g_hash_table_new_full (NULL,
+							   NULL,
+							   (GDestroyNotify) rhythmdb_entry_unref,
+							   NULL);
+	db->priv->added_entries = g_hash_table_new_full (NULL,
+							 NULL,
+							 (GDestroyNotify) rhythmdb_entry_unref,
+							 NULL);
+	db->priv->deleted_entries = g_hash_table_new_full (NULL,
+							   NULL,
+							   (GDestroyNotify) rhythmdb_entry_unref,
+							   NULL);
 
 	db->priv->event_poll_id = g_idle_add ((GSourceFunc) rhythmdb_idle_poll_events, db);
 
@@ -410,7 +427,8 @@ rhythmdb_init (RhythmDB *db)
 
 static void
 rhythmdb_execute_multi_stat_info_cb (GnomeVFSAsyncHandle *handle,
-				     GList *results, /* GnomeVFSGetFileInfoResult* items */
+				     GList *results,
+				     /* GnomeVFSGetFileInfoResult* items */
 				     RhythmDB *db)
 {
 	g_mutex_lock (db->priv->stat_mutex);
@@ -472,14 +490,16 @@ rhythmdb_start_action_thread (RhythmDB *
 }
 
 static void
-rhythmdb_action_free (RhythmDB *db, RhythmDBAction *action)
+rhythmdb_action_free (RhythmDB *db,
+		      RhythmDBAction *action)
 {
 	g_free (action->uri);
 	g_free (action);
 }
 
 static void
-rhythmdb_event_free (RhythmDB *db, RhythmDBEvent *result)
+rhythmdb_event_free (RhythmDB *db,
+		     RhythmDBEvent *result)
 {
 	switch (result->type) {
 	case RHYTHMDB_EVENT_THREAD_EXITED:
@@ -512,6 +532,9 @@ rhythmdb_event_free (RhythmDB *db, Rhyth
 		g_object_unref (result->results);
 	if (result->handle)
 		gnome_vfs_async_cancel (result->handle);
+	if (result->entry != NULL) {
+		rhythmdb_entry_unref (result->entry);
+	}
 	g_free (result);
 }
 
@@ -572,7 +595,7 @@ static void
 rhythmdb_finalize (GObject *object)
 {
 	RhythmDB *db;
-	int i;
+	int  i;
 
 	g_return_if_fail (object != NULL);
 	g_return_if_fail (RHYTHMDB_IS (object));
@@ -625,9 +648,9 @@ rhythmdb_finalize (GObject *object)
 
 static void
 rhythmdb_set_property (GObject *object,
-		      guint prop_id,
-		      const GValue *value,
-		      GParamSpec *pspec)
+		       guint prop_id,
+		       const GValue *value,
+		       GParamSpec *pspec)
 {
 	RhythmDB *source = RHYTHMDB (object);
 
@@ -649,9 +672,9 @@ rhythmdb_set_property (GObject *object,
 
 static void
 rhythmdb_get_property (GObject *object,
-		      guint prop_id,
-		      GValue *value,
-		      GParamSpec *pspec)
+		       guint prop_id,
+		       GValue *value,
+		       GParamSpec *pspec)
 {
 	RhythmDB *source = RHYTHMDB (object);
 
@@ -672,7 +695,9 @@ rhythmdb_get_property (GObject *object,
 }
 
 static void
-rhythmdb_thread_create (RhythmDB *db, GThreadFunc func, gpointer data)
+rhythmdb_thread_create (RhythmDB *db,
+			GThreadFunc func,
+			gpointer data)
 {
 	g_object_ref (db);
 	g_atomic_int_inc (&db->priv->outstanding_threads);
@@ -716,7 +741,9 @@ rhythmdb_read_leave (RhythmDB *db)
 }
 
 static gboolean
-free_entry_changes (RhythmDBEntry *entry, GSList *changes, RhythmDB *db)
+free_entry_changes (RhythmDBEntry *entry,
+		    GSList *changes,
+		    RhythmDB *db)
 {
 	GSList *t;
 	for (t = changes; t; t = t->next) {
@@ -726,17 +753,22 @@ free_entry_changes (RhythmDBEntry *entry
 		g_free (change);
 	}
 	g_slist_free (changes);
+
 	return TRUE;
 }
 
 static void
-emit_entry_changed (RhythmDBEntry *entry, GSList *changes, RhythmDB *db)
+emit_entry_changed (RhythmDBEntry *entry,
+		    GSList *changes,
+		    RhythmDB *db)
 {
 	g_signal_emit (G_OBJECT (db), rhythmdb_signals[ENTRY_CHANGED], 0, entry, changes);
 }
 
 static void
-sync_entry_changed (RhythmDBEntry *entry, GSList *changes, RhythmDB *db)
+sync_entry_changed (RhythmDBEntry *entry,
+		    GSList *changes,
+		    RhythmDB *db)
 {
 	GSList *t;
 
@@ -801,7 +833,9 @@ rhythmdb_emit_entry_signals_idle (Rhythm
 }
 
 static gboolean
-process_added_entries_cb (RhythmDBEntry *entry, GThread *thread, RhythmDB *db)
+process_added_entries_cb (RhythmDBEntry *entry,
+			  GThread *thread,
+			  RhythmDB *db)
 {
 	if (thread != g_thread_self ())
 		return FALSE;
@@ -825,22 +859,28 @@ process_added_entries_cb (RhythmDBEntry 
 
 	rhythmdb_entry_ref (entry);
 	db->priv->added_entries_to_emit = g_list_prepend (db->priv->added_entries_to_emit, entry);
+
 	return TRUE;
 }
 
 static gboolean
-process_deleted_entries_cb (RhythmDBEntry *entry, GThread *thread, RhythmDB *db)
+process_deleted_entries_cb (RhythmDBEntry *entry,
+			    GThread *thread,
+			    RhythmDB *db)
 {
 	if (thread != g_thread_self ())
 		return FALSE;
 
-	/* carry reference over from deleted_entries hash table */
+	rhythmdb_entry_ref (entry);
 	db->priv->deleted_entries_to_emit = g_list_prepend (db->priv->deleted_entries_to_emit, entry);
+
 	return TRUE;
 }
 
 static void
-rhythmdb_commit_internal (RhythmDB *db, gboolean sync_changes, GThread *thread)
+rhythmdb_commit_internal (RhythmDB *db,
+			  gboolean sync_changes,
+			  GThread *thread)
 {
 	g_mutex_lock (db->priv->change_mutex);
 
@@ -878,7 +918,8 @@ timeout_rhythmdb_commit (RhythmDBTimeout
 }
 
 static void
-rhythmdb_add_timeout_commit (RhythmDB *db, gboolean sync)
+rhythmdb_add_timeout_commit (RhythmDB *db,
+			     gboolean sync)
 {
 	RhythmDBTimeoutCommitData *data;
 
@@ -935,7 +976,8 @@ rhythmdb_error_quark (void)
  * Returns: the newly allocated #RhythmDBEntry
  **/
 RhythmDBEntry *
-rhythmdb_entry_allocate (RhythmDB *db, RhythmDBEntryType type)
+rhythmdb_entry_allocate (RhythmDB *db,
+			 RhythmDBEntryType type)
 {
 	RhythmDBEntry *ret;
 	gsize size = sizeof (RhythmDBEntry);
@@ -958,7 +1000,7 @@ rhythmdb_entry_allocate (RhythmDB *db, R
 		      RHYTHMDB_ENTRY_LAST_SEEN_DIRTY;
 
 	/* The refcount is initially 0, we want to set it to 1 */
-	g_atomic_int_inc (&ret->refcount);
+	ret->refcount = 1;
 
 	if (type->post_entry_create)
 		(type->post_entry_create)(ret, type->post_entry_create_data);
@@ -977,8 +1019,11 @@ rhythmdb_entry_allocate (RhythmDB *db, R
  * a slightly more friendly interface to this functionality.
  */
 gpointer
-rhythmdb_entry_get_type_data (RhythmDBEntry *entry, guint expected_size)
+rhythmdb_entry_get_type_data (RhythmDBEntry *entry,
+			      guint expected_size)
 {
+	g_return_val_if_fail (entry != NULL, NULL);
+
 	g_assert (expected_size == entry->type->entry_type_data_size);
 	gsize offset = ALIGN_STRUCT (sizeof (RhythmDBEntry));
 
@@ -996,11 +1041,17 @@ rhythmdb_entry_get_type_data (RhythmDBEn
  * this function.
  **/
 void
-rhythmdb_entry_insert (RhythmDB *db, RhythmDBEntry *entry)
+rhythmdb_entry_insert (RhythmDB *db,
+		       RhythmDBEntry *entry)
 {
+	g_return_if_fail (RHYTHMDB_IS (db));
+	g_return_if_fail (entry != NULL);
+
 	g_assert ((entry->flags & RHYTHMDB_ENTRY_INSERTED) == 0);
 	g_return_if_fail (entry->location != NULL);
 
+	/* ref the entry before adding to hash, it is unreffed when removed */
+	rhythmdb_entry_ref (entry);
 	g_mutex_lock (db->priv->change_mutex);
 	g_hash_table_insert (db->priv->added_entries, entry, g_thread_self ());
 	g_mutex_unlock (db->priv->change_mutex);
@@ -1022,7 +1073,9 @@ rhythmdb_entry_insert (RhythmDB *db, Rhy
  * Returns: the newly created #RhythmDBEntry
  **/
 RhythmDBEntry *
-rhythmdb_entry_new (RhythmDB *db, RhythmDBEntryType type, const char *uri)
+rhythmdb_entry_new (RhythmDB *db,
+		    RhythmDBEntryType type,
+		    const char *uri)
 {
 	RhythmDBEntry *ret;
 	RhythmDBClass *klass = RHYTHMDB_GET_CLASS (db);
@@ -1056,7 +1109,9 @@ rhythmdb_entry_new (RhythmDB *db, Rhythm
  * Returns: the newly created #RhythmDBEntry
  **/
 RhythmDBEntry *
-rhythmdb_entry_example_new (RhythmDB *db, RhythmDBEntryType type, const char *uri)
+rhythmdb_entry_example_new (RhythmDB *db,
+			    RhythmDBEntryType type,
+			    const char *uri)
 {
 	RhythmDBEntry *ret;
 
@@ -1087,8 +1142,11 @@ rhythmdb_entry_example_new (RhythmDB *db
 RhythmDBEntry *
 rhythmdb_entry_ref (RhythmDBEntry *entry)
 {
-	if (entry != NULL)
-		g_atomic_int_inc (&entry->refcount);
+	g_return_val_if_fail (entry != NULL, NULL);
+	g_return_val_if_fail (entry->refcount > 0, NULL);
+
+	g_atomic_int_inc (&entry->refcount);
+
 	return entry;
 }
 
@@ -1098,6 +1156,7 @@ rhythmdb_entry_finalize (RhythmDBEntry *
 	RhythmDBEntryType type;
 
 	type = rhythmdb_entry_get_entry_type (entry);
+
 	if (type->pre_entry_destroy)
 		(type->pre_entry_destroy)(entry, type->pre_entry_destroy_data);
 
@@ -1124,8 +1183,15 @@ rhythmdb_entry_finalize (RhythmDBEntry *
 void
 rhythmdb_entry_unref (RhythmDBEntry *entry)
 {
-	if (entry && g_atomic_int_dec_and_test (&entry->refcount))
+	gboolean is_zero;
+
+	g_return_if_fail (entry != NULL);
+	g_return_if_fail (entry->refcount > 0);
+
+	is_zero = g_atomic_int_dec_and_test (&entry->refcount);
+	if (G_UNLIKELY (is_zero)) {
 		rhythmdb_entry_finalize (entry);
+	}
 }
 
 /**
@@ -1141,10 +1207,14 @@ rhythmdb_entry_unref (RhythmDBEntry *ent
  **/
 
 gboolean
-rhythmdb_entry_is_editable (RhythmDB *db, RhythmDBEntry *entry)
+rhythmdb_entry_is_editable (RhythmDB *db,
+			    RhythmDBEntry *entry)
 {
 	RhythmDBEntryType entry_type;
 
+	g_return_val_if_fail (RHYTHMDB_IS (db), FALSE);
+	g_return_val_if_fail (entry != NULL, FALSE);
+
 	entry_type = rhythmdb_entry_get_entry_type (entry);
 	return entry_type->can_sync_metadata (db, entry, entry_type->can_sync_metadata_data);
 }
@@ -1174,8 +1244,10 @@ set_metadata_string_default_unknown (Rhy
 }
 
 static void
-set_props_from_metadata (RhythmDB *db, RhythmDBEntry *entry,
-			 GnomeVFSFileInfo *vfsinfo, RBMetaData *metadata)
+set_props_from_metadata (RhythmDB *db,
+			 RhythmDBEntry *entry,
+			 GnomeVFSFileInfo *vfsinfo,
+			 RBMetaData *metadata)
 {
 	const char *mime;
 	GValue val = {0,};
@@ -1361,7 +1433,8 @@ is_ghost_entry (RhythmDBEntry *entry)
 }
 
 static void
-rhythmdb_process_stat_event (RhythmDB *db, RhythmDBEvent *event)
+rhythmdb_process_stat_event (RhythmDB *db,
+			     RhythmDBEvent *event)
 {
 	RhythmDBEntry *entry;
 	RhythmDBAction *action;
@@ -1457,7 +1530,8 @@ typedef struct
 } RhythmDBLoadErrorData;
 
 static void
-rhythmdb_add_import_error_entry (RhythmDB *db, RhythmDBEvent *event)
+rhythmdb_add_import_error_entry (RhythmDB *db,
+				 RhythmDBEvent *event)
 {
 	RhythmDBEntry *entry;
 	GValue value = {0,};
@@ -1541,7 +1615,8 @@ rhythmdb_add_import_error_entry (RhythmD
 }
 
 static gboolean
-rhythmdb_process_metadata_load (RhythmDB *db, RhythmDBEvent *event)
+rhythmdb_process_metadata_load (RhythmDB *db,
+				RhythmDBEvent *event)
 {
 	RhythmDBEntry *entry;
 	GValue value = {0,};
@@ -1593,7 +1668,7 @@ rhythmdb_process_metadata_load (RhythmDB
 		g_value_init (&value, G_TYPE_ULONG);
 		g_value_set_ulong (&value, 0);
 		rhythmdb_entry_set (db, entry,
-					       RHYTHMDB_PROP_LAST_PLAYED, &value);
+				    RHYTHMDB_PROP_LAST_PLAYED, &value);
 		g_value_unset (&value);
 
 		/* initialize the rating */
@@ -1662,7 +1737,8 @@ rhythmdb_process_queued_entry_set_event 
 }
 
 static void
-rhythmdb_process_file_created_or_modified (RhythmDB *db, RhythmDBEvent *event)
+rhythmdb_process_file_created_or_modified (RhythmDB *db,
+					   RhythmDBEvent *event)
 {
 	RhythmDBAction *action;
 
@@ -1674,7 +1750,8 @@ rhythmdb_process_file_created_or_modifie
 }
 
 static void
-rhythmdb_process_file_deleted (RhythmDB *db, RhythmDBEvent *event)
+rhythmdb_process_file_deleted (RhythmDB *db,
+			       RhythmDBEvent *event)
 {
 	RhythmDBEntry *entry = rhythmdb_entry_lookup_by_location (db, event->uri);
 
@@ -1688,7 +1765,8 @@ rhythmdb_process_file_deleted (RhythmDB 
 }
 
 static gboolean
-rhythmdb_process_events (RhythmDB *db, GTimeVal *timeout)
+rhythmdb_process_events (RhythmDB *db,
+			 GTimeVal *timeout)
 {
 	RhythmDBEvent *event;
 	guint count = 0;
@@ -1833,7 +1911,8 @@ read_queue (GAsyncQueue *queue, gboolean
 
 static void
 rhythmdb_execute_stat_info_cb (GnomeVFSAsyncHandle *handle,
-			       GList *results, /* GnomeVFSGetFileInfoResult* items */
+			       GList *results,
+			       /* GnomeVFSGetFileInfoResult* items */
 			       RhythmDBEvent *event)
 {
 	/* this is in the main thread, so we can't do any long operation here */
@@ -1861,7 +1940,9 @@ rhythmdb_execute_stat_info_cb (GnomeVFSA
 }
 
 static void
-rhythmdb_execute_stat (RhythmDB *db, const char *uri, RhythmDBEvent *event)
+rhythmdb_execute_stat (RhythmDB *db,
+		       const char *uri,
+		       RhythmDBEvent *event)
 {
 	GnomeVFSURI *vfs_uri = gnome_vfs_uri_new (uri);
 
@@ -1882,7 +1963,9 @@ rhythmdb_execute_stat (RhythmDB *db, con
 }
 
 void
-queue_stat_uri (const char *uri, RhythmDB *db, RhythmDBEntryType type)
+queue_stat_uri (const char *uri,
+		RhythmDB *db,
+		RhythmDBEntryType type)
 {
 	RhythmDBEvent *result;
 
@@ -1929,7 +2012,8 @@ queue_stat_uri (const char *uri, RhythmD
 }
 
 static void
-queue_stat_uri_tad (const char *uri, RhythmDBAddThreadData *data)
+queue_stat_uri_tad (const char *uri,
+		    RhythmDBAddThreadData *data)
 {
 	queue_stat_uri (uri, data->db, data->type);
 }
@@ -1953,7 +2037,9 @@ add_thread_main (RhythmDBAddThreadData *
 }
 
 static void
-rhythmdb_execute_load (RhythmDB *db, const char *uri, RhythmDBEvent *event)
+rhythmdb_execute_load (RhythmDB *db,
+		       const char *uri,
+		       RhythmDBEvent *event)
 {
 	GnomeVFSURI *vfs_uri = gnome_vfs_uri_new (uri);
 	GnomeVFSResult vfsresult;
@@ -1997,9 +2083,15 @@ rhythmdb_execute_load (RhythmDB *db, con
  * Gets a property of an entry, storing it in the given #GValue.
  **/
 void
-rhythmdb_entry_get (RhythmDB *db, RhythmDBEntry *entry,
-		    RhythmDBPropType propid, GValue *val)
+rhythmdb_entry_get (RhythmDB *db,
+		    RhythmDBEntry *entry,
+		    RhythmDBPropType propid,
+		    GValue *val)
 {
+	g_return_if_fail (RHYTHMDB_IS (db));
+	g_return_if_fail (entry != NULL);
+	g_return_if_fail (entry->refcount > 0);
+
 	rhythmdb_entry_sync_mirrored (entry, propid);
 
 	g_assert (G_VALUE_TYPE (val) == rhythmdb_get_property_type (db, propid));
@@ -2029,7 +2121,9 @@ rhythmdb_entry_get (RhythmDB *db, Rhythm
 }
 
 static void
-entry_to_rb_metadata (RhythmDB *db, RhythmDBEntry *entry, RBMetaData *metadata)
+entry_to_rb_metadata (RhythmDB *db,
+		      RhythmDBEntry *entry,
+		      RBMetaData *metadata)
 {
 	GValue val = {0, };
 	int i;
@@ -2165,13 +2259,16 @@ action_thread_main (RhythmDB *db)
  * If the URI is that of a directory, everything under it will be added recursively.
  **/
 void
-rhythmdb_add_uri (RhythmDB *db, const char *uri)
+rhythmdb_add_uri (RhythmDB *db,
+		  const char *uri)
 {
 	rhythmdb_add_uri_with_type (db, uri, RHYTHMDB_ENTRY_TYPE_INVALID);
 }
 
 void
-rhythmdb_add_uri_with_type (RhythmDB *db, const char *uri, RhythmDBEntryType type)
+rhythmdb_add_uri_with_type (RhythmDB *db,
+			    const char *uri,
+			    RhythmDBEntryType type)
 {
 	char *realuri;
 	char *canon_uri;
@@ -2183,14 +2280,15 @@ rhythmdb_add_uri_with_type (RhythmDB *db
 	if (rb_uri_is_directory (realuri)) {
 		RhythmDBAddThreadData *data = g_new0 (RhythmDBAddThreadData, 1);
 		data->db = db;
-		data->uri = realuri;
+		data->uri = g_strdup (realuri);
 		data->type = type;
 
 		rhythmdb_thread_create (db, (GThreadFunc) add_thread_main, data);
 	} else {
 		queue_stat_uri (realuri, db, type);
-		g_free (realuri);
 	}
+
+	g_free (realuri);
 }
 
 static gboolean
@@ -2367,9 +2465,14 @@ rhythmdb_save (RhythmDB *db)
  * have taken effect.
  **/
 void
-rhythmdb_entry_set (RhythmDB *db, RhythmDBEntry *entry,
-		    guint propid, const GValue *value)
+rhythmdb_entry_set (RhythmDB *db,
+		    RhythmDBEntry *entry,
+		    guint propid,
+		    const GValue *value)
 {
+	g_return_if_fail (RHYTHMDB_IS (db));
+	g_return_if_fail (entry != NULL);
+
 	if ((entry->flags & RHYTHMDB_ENTRY_INSERTED) != 0) {
 		if (!rhythmdb_get_readonly (db) && rb_is_main_thread ()) {
 			rhythmdb_entry_set_internal (db, entry, TRUE, propid, value);
@@ -2382,7 +2485,7 @@ rhythmdb_entry_set (RhythmDB *db, Rhythm
 
 			rb_debug ("queuing RHYTHMDB_ACTION_ENTRY_SET");
 
-			result->entry = entry;
+			result->entry = rhythmdb_entry_ref (entry);
 			result->change.prop = propid;
 			result->signal_change = TRUE;
 			g_value_init (&result->change.new, G_VALUE_TYPE (value));
@@ -2395,8 +2498,10 @@ rhythmdb_entry_set (RhythmDB *db, Rhythm
 }
 
 static void
-record_entry_change (RhythmDB *db, RhythmDBEntry *entry,
-		     guint propid, const GValue *value)
+record_entry_change (RhythmDB *db,
+		     RhythmDBEntry *entry,
+		     guint propid,
+		     const GValue *value)
 {
 	RhythmDBEntryChange *changedata;
 	GSList *changelist;
@@ -2418,6 +2523,8 @@ record_entry_change (RhythmDB *db, Rhyth
 	g_value_copy (value, &changedata->new);
 
 	g_mutex_lock (db->priv->change_mutex);
+	/* ref the entry before adding to hash, it is unreffed when removed */
+	rhythmdb_entry_ref (entry);
 	changelist = g_hash_table_lookup (db->priv->changed_entries, entry);
 	changelist = g_slist_append (changelist, changedata);
 	g_hash_table_insert (db->priv->changed_entries, entry, changelist);
@@ -2425,9 +2532,11 @@ record_entry_change (RhythmDB *db, Rhyth
 }
 
 void
-rhythmdb_entry_set_internal (RhythmDB *db, RhythmDBEntry *entry,
+rhythmdb_entry_set_internal (RhythmDB *db,
+			     RhythmDBEntry *entry,
 			     gboolean notify_if_inserted,
-			     guint propid, const GValue *value)
+			     guint propid,
+			     const GValue *value)
 {
 	RhythmDBClass *klass = RHYTHMDB_GET_CLASS (db);
 	gboolean handled;
@@ -2467,19 +2576,27 @@ rhythmdb_entry_set_internal (RhythmDB *d
 			g_assert_not_reached ();
 			break;
 		case RHYTHMDB_PROP_TITLE:
-			rb_refstring_unref (entry->title);
+			if (entry->title != NULL) {
+				rb_refstring_unref (entry->title);
+			}
 			entry->title = rb_refstring_new (g_value_get_string (value));
 			break;
 		case RHYTHMDB_PROP_ALBUM:
-			rb_refstring_unref (entry->album);
+			if (entry->album != NULL) {
+				rb_refstring_unref (entry->album);
+			}
 			entry->album = rb_refstring_new (g_value_get_string (value));
 			break;
 		case RHYTHMDB_PROP_ARTIST:
-			rb_refstring_unref (entry->artist);
+			if (entry->artist != NULL) {
+				rb_refstring_unref (entry->artist);
+			}
 			entry->artist = rb_refstring_new (g_value_get_string (value));
 			break;
 		case RHYTHMDB_PROP_GENRE:
-			rb_refstring_unref (entry->genre);
+			if (entry->genre != NULL) {
+				rb_refstring_unref (entry->genre);
+			}
 			entry->genre = rb_refstring_new (g_value_get_string (value));
 			break;
 		case RHYTHMDB_PROP_TRACK_NUMBER:
@@ -2528,15 +2645,18 @@ rhythmdb_entry_set_internal (RhythmDB *d
 				entry->playback_error = NULL;
 			break;
 		case RHYTHMDB_PROP_MOUNTPOINT:
-			rb_refstring_unref (entry->mountpoint);
+			if (entry->mountpoint != NULL) {
+				rb_refstring_unref (entry->mountpoint);
+			}
 			entry->mountpoint = rb_refstring_new (g_value_get_string (value));
 			break;
 		case RHYTHMDB_PROP_FILE_SIZE:
 			entry->file_size = g_value_get_uint64 (value);
 			break;
 		case RHYTHMDB_PROP_MIMETYPE:
-			if (entry->mimetype)
+			if (entry->mimetype != NULL) {
 				rb_refstring_unref (entry->mimetype);
+			}
 			entry->mimetype = rb_refstring_new (g_value_get_string (value));
 			break;
 		case RHYTHMDB_PROP_MTIME:
@@ -2593,17 +2713,23 @@ rhythmdb_entry_set_internal (RhythmDB *d
 			break;
 		case RHYTHMDB_PROP_LANG:
 			g_assert (podcast);
-			rb_refstring_unref (podcast->lang);
+			if (podcast->lang != NULL) {
+				rb_refstring_unref (podcast->lang);
+			}
 			podcast->lang = rb_refstring_new (g_value_get_string (value));
 			break;
 		case RHYTHMDB_PROP_COPYRIGHT:
 			g_assert (podcast);
-			rb_refstring_unref (podcast->copyright);
+			if (podcast->copyright != NULL) {
+				rb_refstring_unref (podcast->copyright);
+			}
 			podcast->copyright = rb_refstring_new (g_value_get_string (value));
 			break;
 		case RHYTHMDB_PROP_IMAGE:
 			g_assert (podcast);
-			rb_refstring_unref (podcast->image);
+			if (podcast->image != NULL) {
+				rb_refstring_unref (podcast->image);
+			}
 			podcast->image = rb_refstring_new (g_value_get_string (value));
 			break;
 		case RHYTHMDB_PROP_POST_TIME:
@@ -2634,7 +2760,8 @@ rhythmdb_entry_set_internal (RhythmDB *d
  **/
 
 static void
-rhythmdb_entry_sync_mirrored (RhythmDBEntry *entry, guint propid)
+rhythmdb_entry_sync_mirrored (RhythmDBEntry *entry,
+			      guint propid)
 {
 	static const char *format;
 	static const char *never;
@@ -2663,10 +2790,13 @@ rhythmdb_entry_sync_mirrored (RhythmDBEn
 			g_free (val);
 		}
 
-		if (g_atomic_pointer_compare_and_exchange (&entry->last_played_str, old, new))
-			rb_refstring_unref (old);
-		else
+		if (g_atomic_pointer_compare_and_exchange (&entry->last_played_str, old, new)) {
+			if (old != NULL) {
+				rb_refstring_unref (old);
+			}
+		} else {
 			rb_refstring_unref (new);
+		}
 
 		break;
 	}
@@ -2682,10 +2812,14 @@ rhythmdb_entry_sync_mirrored (RhythmDBEn
 		new = rb_refstring_new (val);
 		g_free (val);
 
-		if (g_atomic_pointer_compare_and_exchange (&entry->first_seen_str, old, new))
-			rb_refstring_unref (old);
-		else
+		if (g_atomic_pointer_compare_and_exchange (&entry->first_seen_str, old, new)) {
+			if (old != NULL) {
+				rb_refstring_unref (old);
+			}
+		} else {
 			rb_refstring_unref (new);
+		}
+
 		break;
 	}
 	case RHYTHMDB_PROP_LAST_SEEN_STR:
@@ -2705,10 +2839,14 @@ rhythmdb_entry_sync_mirrored (RhythmDBEn
 			new = NULL;
 		}
 
-		if (g_atomic_pointer_compare_and_exchange (&entry->first_seen_str, old, new))
-			rb_refstring_unref (old);
-		else
+		if (g_atomic_pointer_compare_and_exchange (&entry->first_seen_str, old, new)) {
+			if (old != NULL) {
+				rb_refstring_unref (old);
+			}
+		} else {
 			rb_refstring_unref (new);
+		}
+
 		break;
 	}
 	default:
@@ -2726,12 +2864,17 @@ rhythmdb_entry_sync_mirrored (RhythmDBEn
  * as a network source.
  **/
 void
-rhythmdb_entry_delete (RhythmDB *db, RhythmDBEntry *entry)
+rhythmdb_entry_delete (RhythmDB *db,
+		       RhythmDBEntry *entry)
 {
 	RhythmDBClass *klass = RHYTHMDB_GET_CLASS (db);
 
+	g_return_if_fail (RHYTHMDB_IS (db));
+	g_return_if_fail (entry != NULL);
+
 	klass->impl_entry_delete (db, entry);
 
+	/* ref the entry before adding to hash, it is unreffed when removed */
 	rhythmdb_entry_ref (entry);
 	g_mutex_lock (db->priv->change_mutex);
 	g_hash_table_insert (db->priv->deleted_entries, entry, g_thread_self ());
@@ -2742,7 +2885,8 @@ rhythmdb_entry_delete (RhythmDB *db, Rhy
 }
 
 static gint
-rhythmdb_entry_move_to_trash_cb (GnomeVFSXferProgressInfo *info, gpointer data)
+rhythmdb_entry_move_to_trash_cb (GnomeVFSXferProgressInfo *info,
+				 gpointer data)
 {
 	/* Abort immediately if anything happens */
 	if (info->status == GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR)
@@ -2754,7 +2898,8 @@ rhythmdb_entry_move_to_trash_cb (GnomeVF
 }
 
 static void
-rhythmdb_entry_move_to_trash_set_error (RhythmDB *db, RhythmDBEntry *entry,
+rhythmdb_entry_move_to_trash_set_error (RhythmDB *db,
+					RhythmDBEntry *entry,
 				        GnomeVFSResult res)
 {
 	GValue value = { 0, };
@@ -2772,7 +2917,8 @@ rhythmdb_entry_move_to_trash_set_error (
 }
 
 void
-rhythmdb_entry_move_to_trash (RhythmDB *db, RhythmDBEntry *entry)
+rhythmdb_entry_move_to_trash (RhythmDB *db,
+			      RhythmDBEntry *entry)
 {
 	GnomeVFSResult res;
 	GnomeVFSURI *uri, *trash, *dest;
@@ -2865,7 +3011,8 @@ rhythmdb_entry_move_to_trash (RhythmDB *
  * removable media being removed, or a network share becoming unavailable.
  **/
 void
-rhythmdb_entry_delete_by_type (RhythmDB *db, RhythmDBEntryType type)
+rhythmdb_entry_delete_by_type (RhythmDB *db,
+			       RhythmDBEntryType type)
 {
 	RhythmDBClass *klass = RHYTHMDB_GET_CLASS (db);
 
@@ -2877,13 +3024,15 @@ rhythmdb_entry_delete_by_type (RhythmDB 
 }
 
 const xmlChar *
-rhythmdb_nice_elt_name_from_propid (RhythmDB *db, RhythmDBPropType propid)
+rhythmdb_nice_elt_name_from_propid (RhythmDB *db,
+				    RhythmDBPropType propid)
 {
 	return db->priv->column_xml_names[propid];
 }
 
 int
-rhythmdb_propid_from_nice_elt_name (RhythmDB *db, const xmlChar *name)
+rhythmdb_propid_from_nice_elt_name (RhythmDB *db,
+				    const xmlChar *name)
 {
 	gpointer ret, orig;
 	if (g_hash_table_lookup_extended (db->priv->propname_map, name,
@@ -2903,7 +3052,8 @@ rhythmdb_propid_from_nice_elt_name (Rhyt
  * Returns: the entry with location @uri, or NULL if no such entry exists.
  **/
 RhythmDBEntry *
-rhythmdb_entry_lookup_by_location (RhythmDB *db, const char *uri)
+rhythmdb_entry_lookup_by_location (RhythmDB *db,
+				   const char *uri)
 {
 	RhythmDBClass *klass = RHYTHMDB_GET_CLASS (db);
 
@@ -2919,7 +3069,9 @@ rhythmdb_entry_lookup_by_location (Rhyth
  * Calls the given function for each of the entries in the database.
  **/
 void
-rhythmdb_entry_foreach (RhythmDB *db, GFunc func, gpointer data)
+rhythmdb_entry_foreach (RhythmDB *db,
+			GFunc func,
+			gpointer data)
 {
 	RhythmDBClass *klass = RHYTHMDB_GET_CLASS (db);
 
@@ -2937,7 +3089,9 @@ rhythmdb_entry_foreach (RhythmDB *db, GF
  * Returns: whether the given entry matches the criteria of the given query.
  **/
 gboolean
-rhythmdb_evaluate_query (RhythmDB *db, GPtrArray *query, RhythmDBEntry *entry)
+rhythmdb_evaluate_query (RhythmDB *db,
+			 GPtrArray *query,
+			 RhythmDBEntry *entry)
 {
 	RhythmDBClass *klass = RHYTHMDB_GET_CLASS (db);
 
@@ -3194,7 +3348,8 @@ rhythmdb_prop_type_get_type (void)
 }
 
 void
-rhythmdb_emit_entry_deleted (RhythmDB *db, RhythmDBEntry *entry)
+rhythmdb_emit_entry_deleted (RhythmDB *db,
+			     RhythmDBEntry *entry)
 {
 	g_signal_emit (G_OBJECT (db), rhythmdb_signals[ENTRY_DELETED], 0, entry);
 }
@@ -3232,7 +3387,11 @@ rhythmdb_is_busy (RhythmDB *db)
  * Returns: the string, which should be freed with g_free.
  **/
 char *
-rhythmdb_compute_status_normal (gint n_songs, glong duration, guint64 size, const char *singular, const char *plural)
+rhythmdb_compute_status_normal (gint n_songs,
+				glong duration,
+				guint64 size,
+				const char *singular,
+				const char *plural)
 {
 	long days, hours, minutes, seconds;
 	char *songcount = NULL;
@@ -3315,7 +3474,10 @@ rhythmdb_compute_status_normal (gint n_s
 }
 
 static void
-default_sync_metadata (RhythmDB *db, RhythmDBEntry *entry, GError **error, gpointer data)
+default_sync_metadata (RhythmDB *db,
+		       RhythmDBEntry *entry,
+		       GError **error,
+		       gpointer data)
 {
 	const char *uri;
 	GError *local_error = NULL;
@@ -3356,7 +3518,8 @@ default_sync_metadata (RhythmDB *db, Rhy
  * Returns: the new #RhythmDBEntryType.
  **/
 RhythmDBEntryType
-rhythmdb_entry_register_type (RhythmDB *db, const char *name)
+rhythmdb_entry_register_type (RhythmDB *db,
+			      const char *name)
 {
 	RhythmDBEntryType type;
 	RhythmDBClass *klass = RHYTHMDB_GET_CLASS (db);
@@ -3415,7 +3578,9 @@ rhythmdb_entry_type_foreach_cb (const ch
  * Calls a function for each registered entry type.
  */
 void
-rhythmdb_entry_type_foreach (RhythmDB *db, GHFunc func, gpointer data)
+rhythmdb_entry_type_foreach (RhythmDB *db,
+			     GHFunc func,
+			     gpointer data)
 {
 	RhythmDBEntryTypeForeachData d;
 
@@ -3441,7 +3606,8 @@ rhythmdb_entry_type_foreach (RhythmDB *d
  * Returns: the #RhythmDBEntryType
  */
 RhythmDBEntryType
-rhythmdb_entry_type_get_by_name (RhythmDB *db, const char *name)
+rhythmdb_entry_type_get_by_name (RhythmDB *db,
+				 const char *name)
 {
 	gpointer t = NULL;
 
@@ -3458,7 +3624,9 @@ rhythmdb_entry_type_get_by_name (RhythmD
 }
 
 static gboolean
-song_can_sync_metadata (RhythmDB *db, RhythmDBEntry *entry, gpointer data)
+song_can_sync_metadata (RhythmDB *db,
+			RhythmDBEntry *entry,
+			gpointer data)
 {
 	const char *mimetype;
 
@@ -3467,13 +3635,15 @@ song_can_sync_metadata (RhythmDB *db, Rh
 }
 
 static char *
-podcast_get_playback_uri (RhythmDBEntry *entry, gpointer data)
+podcast_get_playback_uri (RhythmDBEntry *entry,
+			  gpointer data)
 {
 	return rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_MOUNTPOINT);
 }
 
 static void
-podcast_data_destroy (RhythmDBEntry *entry, gpointer something)
+podcast_data_destroy (RhythmDBEntry *entry,
+		      gpointer something)
 {
 	RhythmDBPodcastFields *podcast = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RhythmDBPodcastFields);
 	rb_refstring_unref (podcast->description);
@@ -3567,7 +3737,8 @@ rhythmdb_entry_podcast_feed_get_type (vo
 }
 
 static void
-rhythmdb_entry_set_mount_point (RhythmDB *db, RhythmDBEntry *entry,
+rhythmdb_entry_set_mount_point (RhythmDB *db,
+				RhythmDBEntry *entry,
 				const gchar *realuri)
 {
 	gchar *mount_point;
@@ -3585,12 +3756,16 @@ rhythmdb_entry_set_mount_point (RhythmDB
 }
 
 void
-rhythmdb_entry_set_visibility (RhythmDB *db, RhythmDBEntry *entry,
+rhythmdb_entry_set_visibility (RhythmDB *db,
+			       RhythmDBEntry *entry,
 			       gboolean visible)
 {
 	GValue old_val = {0, };
 	gboolean old_visible;
 
+	g_return_if_fail (RHYTHMDB_IS (db));
+	g_return_if_fail (entry != NULL);
+
 	g_value_init (&old_val, G_TYPE_BOOLEAN);
 
 	rhythmdb_entry_get (db, entry, RHYTHMDB_PROP_HIDDEN, &old_val);
@@ -3658,21 +3833,30 @@ library_location_changed_cb (GConfClient
 }
 
 char *
-rhythmdb_entry_dup_string (RhythmDBEntry *entry, RhythmDBPropType propid)
+rhythmdb_entry_dup_string (RhythmDBEntry *entry,
+			   RhythmDBPropType propid)
 {
 	const char *s;
 
+	g_return_val_if_fail (entry != NULL, NULL);
+
 	s = rhythmdb_entry_get_string (entry, propid);
-	if (s)
+	if (s != NULL) {
 		return g_strdup (s);
-	else
+	} else {
 		return NULL;
+	}
 }
 
 const char *
-rhythmdb_entry_get_string (RhythmDBEntry *entry, RhythmDBPropType propid)
+rhythmdb_entry_get_string (RhythmDBEntry *entry,
+			   RhythmDBPropType propid)
 {
 	RhythmDBPodcastFields *podcast = NULL;
+
+	g_return_val_if_fail (entry != NULL, NULL);
+	g_return_val_if_fail (entry->refcount > 0, NULL);
+
 	if (entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_FEED ||
 	    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_POST)
 		podcast = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RhythmDBPodcastFields);
@@ -3761,8 +3945,11 @@ rhythmdb_entry_get_string (RhythmDBEntry
 }
 
 gboolean
-rhythmdb_entry_get_boolean (RhythmDBEntry *entry, RhythmDBPropType propid)
+rhythmdb_entry_get_boolean (RhythmDBEntry *entry,
+			    RhythmDBPropType propid)
 {
+	g_return_val_if_fail (entry != NULL, FALSE);
+
 	switch (propid) {
 	case RHYTHMDB_PROP_HIDDEN:
 		return ((entry->flags & RHYTHMDB_ENTRY_HIDDEN) != 0);
@@ -3773,8 +3960,11 @@ rhythmdb_entry_get_boolean (RhythmDBEntr
 }
 
 guint64
-rhythmdb_entry_get_uint64 (RhythmDBEntry *entry, RhythmDBPropType propid)
+rhythmdb_entry_get_uint64 (RhythmDBEntry *entry,
+			   RhythmDBPropType propid)
 {
+	g_return_val_if_fail (entry != NULL, 0);
+
 	switch (propid) {
 	case RHYTHMDB_PROP_FILE_SIZE:
 		return entry->file_size;
@@ -3787,12 +3977,17 @@ rhythmdb_entry_get_uint64 (RhythmDBEntry
 RhythmDBEntryType
 rhythmdb_entry_get_entry_type (RhythmDBEntry *entry)
 {
+	g_return_val_if_fail (entry != NULL, RHYTHMDB_ENTRY_TYPE_INVALID);
+
 	return entry->type;
 }
 
 gpointer
-rhythmdb_entry_get_pointer (RhythmDBEntry *entry, RhythmDBPropType propid)
+rhythmdb_entry_get_pointer (RhythmDBEntry *entry,
+			    RhythmDBPropType propid)
 {
+	g_return_val_if_fail (entry != NULL, NULL);
+
 	switch (propid) {
 	case RHYTHMDB_PROP_TYPE:
 		return entry->type;
@@ -3803,9 +3998,13 @@ rhythmdb_entry_get_pointer (RhythmDBEntr
 }
 
 gulong
-rhythmdb_entry_get_ulong (RhythmDBEntry *entry, RhythmDBPropType propid)
+rhythmdb_entry_get_ulong (RhythmDBEntry *entry,
+			  RhythmDBPropType propid)
 {
 	RhythmDBPodcastFields *podcast = NULL;
+
+	g_return_val_if_fail (entry != NULL, 0);
+
 	if (entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_FEED ||
 	    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_POST)
 		podcast = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RhythmDBPodcastFields);
@@ -3856,8 +4055,11 @@ rhythmdb_entry_get_ulong (RhythmDBEntry 
 }
 
 double
-rhythmdb_entry_get_double (RhythmDBEntry *entry, RhythmDBPropType propid)
+rhythmdb_entry_get_double (RhythmDBEntry *entry,
+			   RhythmDBPropType propid)
 {
+	g_return_val_if_fail (entry != NULL, 0);
+
 	switch (propid) {
 	case RHYTHMDB_PROP_TRACK_GAIN:
 		return entry->track_gain;
@@ -3880,6 +4082,8 @@ rhythmdb_entry_get_playback_uri (RhythmD
 {
 	RhythmDBEntryType type;
 
+	g_return_val_if_fail (entry != NULL, NULL);
+
 	type = rhythmdb_entry_get_entry_type (entry);
 	if (type->get_playback_uri)
 		return (type->get_playback_uri) (entry, type->get_playback_uri_data);
@@ -3888,7 +4092,8 @@ rhythmdb_entry_get_playback_uri (RhythmD
 }
 
 GType
-rhythmdb_get_property_type (RhythmDB *db, guint property_id)
+rhythmdb_get_property_type (RhythmDB *db,
+			    guint property_id)
 {
 	g_assert (property_id >= 0 && property_id < RHYTHMDB_NUM_PROPERTIES);
 	return rhythmdb_property_type_map[property_id];
Index: rhythmdb/rhythmdb.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/rhythmdb/rhythmdb.h,v
retrieving revision 1.93
diff -p -u -r1.93 rhythmdb.h
--- rhythmdb/rhythmdb.h	18 Jul 2006 12:37:30 -0000	1.93
+++ rhythmdb/rhythmdb.h	21 Jul 2006 21:31:31 -0000
@@ -48,7 +48,6 @@ GType rhythmdb_entry_get_type (void);
 
 #define RHYTHMDB_TYPE_ENTRY      (rhythmdb_entry_get_type ())
 #define RHYTHMDB_ENTRY(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), RHYTHMDB_TYPE_ENTRY, RhythmDBEntry))
-#define RHYTHMDB_IS_ENTRY(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), RHYTHMDB_TYPE_ENTRY))
 
 typedef void (*RhythmDBEntryActionFunc) (RhythmDBEntry *entry, gpointer data);
 typedef char* (*RhythmDBEntryStringFunc) (RhythmDBEntry *entry, gpointer data);
Index: shell/rb-play-order-linear-loop.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-play-order-linear-loop.c,v
retrieving revision 1.5
diff -p -u -r1.5 rb-play-order-linear-loop.c
--- shell/rb-play-order-linear-loop.c	14 Jul 2006 12:30:49 -0000	1.5
+++ shell/rb-play-order-linear-loop.c	21 Jul 2006 21:31:31 -0000
@@ -59,8 +59,8 @@ rb_linear_play_order_loop_init (RBLinear
 {
 }
 
-static RhythmDBEntry*
-rb_linear_play_order_loop_get_next (RBPlayOrder* porder)
+static RhythmDBEntry *
+rb_linear_play_order_loop_get_next (RBPlayOrder *porder)
 {
 	RhythmDBQueryModel *model;
 	RhythmDBEntry *entry;
@@ -73,13 +73,15 @@ rb_linear_play_order_loop_get_next (RBPl
 		return NULL;
 
 	g_object_get (porder, "playing-entry", &entry, NULL);
-	if (entry) {
+
+	if (entry != NULL) {
 		RhythmDBEntry *next;
 
 		next = rhythmdb_query_model_get_next_from_entry (model, entry);
 		rhythmdb_entry_unref (entry);
 		entry = next;
 	}
+
 	if (entry == NULL) {
 		/* loop back to (or start from) the first entry */
 		GtkTreeIter iter;
@@ -91,8 +93,8 @@ rb_linear_play_order_loop_get_next (RBPl
 	return entry;
 }
 
-static RhythmDBEntry*
-rb_linear_play_order_loop_get_previous (RBPlayOrder* porder)
+static RhythmDBEntry *
+rb_linear_play_order_loop_get_previous (RBPlayOrder *porder)
 {
 	RhythmDBQueryModel *model;
 	RhythmDBEntry *entry;
@@ -106,7 +108,7 @@ rb_linear_play_order_loop_get_previous (
 		return NULL;
 
 	g_object_get (porder, "playing-entry", &entry, NULL);
-	if (entry) {
+	if (entry != NULL) {
 		prev = rhythmdb_query_model_get_previous_from_entry (model, entry);
 		rhythmdb_entry_unref (entry);
 	}
@@ -119,5 +121,6 @@ rb_linear_play_order_loop_get_previous (
 			return NULL;
 		prev = rhythmdb_query_model_iter_to_entry (model, &iter);
 	}
+
 	return prev;
 }
Index: shell/rb-play-order-linear.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-play-order-linear.c,v
retrieving revision 1.7
diff -p -u -r1.7 rb-play-order-linear.c
--- shell/rb-play-order-linear.c	14 Jul 2006 12:30:49 -0000	1.7
+++ shell/rb-play-order-linear.c	21 Jul 2006 21:31:31 -0000
@@ -19,6 +19,8 @@
  *
  */
 
+#include "config.h"
+
 #include "rb-play-order-linear.h"
 
 #include "rb-debug.h"
@@ -27,8 +29,8 @@
 
 static void rb_linear_play_order_class_init (RBLinearPlayOrderClass *klass);
 
-static RhythmDBEntry* rb_linear_play_order_get_next (RBPlayOrder* method);
-static RhythmDBEntry* rb_linear_play_order_get_previous (RBPlayOrder* method);
+static RhythmDBEntry *rb_linear_play_order_get_next (RBPlayOrder *method);
+static RhythmDBEntry *rb_linear_play_order_get_previous (RBPlayOrder *method);
 
 G_DEFINE_TYPE (RBLinearPlayOrder, rb_linear_play_order, RB_TYPE_PLAY_ORDER)
 
@@ -57,8 +59,8 @@ rb_linear_play_order_init (RBLinearPlayO
 {
 }
 
-static RhythmDBEntry*
-rb_linear_play_order_get_next (RBPlayOrder* porder)
+static RhythmDBEntry *
+rb_linear_play_order_get_next (RBPlayOrder *porder)
 {
 	RhythmDBQueryModel *model;
 	RhythmDBEntry *entry;
@@ -70,8 +72,8 @@ rb_linear_play_order_get_next (RBPlayOrd
 	if (model == NULL)
 		return NULL;
 
-	g_object_get (porder, "playing-entry", &entry, NULL);
-	if (entry) {
+        entry = rb_play_order_get_playing_entry (porder);
+	if (entry != NULL) {
 		RhythmDBEntry *next;
 		next = rhythmdb_query_model_get_next_from_entry (model, entry);
 		rhythmdb_entry_unref (entry);
@@ -84,8 +86,8 @@ rb_linear_play_order_get_next (RBPlayOrd
 	}
 }
 
-static RhythmDBEntry*
-rb_linear_play_order_get_previous (RBPlayOrder* porder)
+static RhythmDBEntry *
+rb_linear_play_order_get_previous (RBPlayOrder *porder)
 {
 	RhythmDBQueryModel *model;
 	RhythmDBEntry *entry, *prev;
@@ -97,11 +99,12 @@ rb_linear_play_order_get_previous (RBPla
 	if (model == NULL)
 		return NULL;
 
-	g_object_get (porder, "playing-entry", &entry, NULL);
+        entry = rb_play_order_get_playing_entry (porder);
 	if (entry == NULL)
 		return NULL;
 
 	prev = rhythmdb_query_model_get_previous_from_entry (model, entry);
 	rhythmdb_entry_unref (entry);
+
 	return prev;
 }
Index: shell/rb-play-order-queue.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-play-order-queue.c,v
retrieving revision 1.5
diff -p -u -r1.5 rb-play-order-queue.c
--- shell/rb-play-order-queue.c	14 Jul 2006 12:30:49 -0000	1.5
+++ shell/rb-play-order-queue.c	21 Jul 2006 21:31:31 -0000
@@ -17,6 +17,8 @@
  *
  */
 
+#include "config.h"
+
 #include "rb-play-order-queue.h"
 
 #include "rb-debug.h"
@@ -75,7 +77,7 @@ rb_queue_play_order_init (RBQueuePlayOrd
 {
 }
 
-static RhythmDBEntry*
+static RhythmDBEntry *
 rb_queue_play_order_get_next (RBPlayOrder* porder)
 {
 	RhythmDBQueryModel *model;
@@ -118,7 +120,7 @@ rb_queue_play_order_go_next (RBPlayOrder
 }
 
 static RhythmDBEntry*
-rb_queue_play_order_get_previous (RBPlayOrder* porder)
+rb_queue_play_order_get_previous (RBPlayOrder *porder)
 {
 	RhythmDBQueryModel *model;
 	RhythmDBEntry *entry, *prev;
Index: shell/rb-play-order-random.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-play-order-random.c,v
retrieving revision 1.10
diff -p -u -r1.10 rb-play-order-random.c
--- shell/rb-play-order-random.c	17 Jul 2006 14:52:29 -0000	1.10
+++ shell/rb-play-order-random.c	21 Jul 2006 21:31:31 -0000
@@ -180,8 +180,10 @@ get_query_model_contents (RBRandomPlayOr
 	i = 0;
 	do {
 		RhythmDBEntry *entry = rhythmdb_query_model_iter_to_entry (model, &iter);
-		if (!entry)
+
+		if (entry == NULL)
 			continue;
+
 		weight = rb_random_play_order_get_entry_weight (rorder, db, entry);
 
 		g_array_index (result, EntryWeight, i).entry = entry;
@@ -189,6 +191,9 @@ get_query_model_contents (RBRandomPlayOr
 		g_array_index (result, EntryWeight, i).cumulative_weight = cumulative_weight;
 		cumulative_weight += weight;
 		i++;
+
+		rhythmdb_entry_unref (entry);
+
 	} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter));
 
 	return result;
Index: shell/rb-play-order-shuffle.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-play-order-shuffle.c,v
retrieving revision 1.11
diff -p -u -r1.11 rb-play-order-shuffle.c
--- shell/rb-play-order-shuffle.c	14 Jul 2006 12:30:49 -0000	1.11
+++ shell/rb-play-order-shuffle.c	21 Jul 2006 21:31:31 -0000
@@ -281,6 +281,7 @@ handle_query_model_changed (RBShufflePla
 			RhythmDBEntry *entry;
 			entry = rhythmdb_query_model_iter_to_entry (model, &iter);
 			rb_shuffle_entry_added (RB_PLAY_ORDER (sorder), entry);
+			rhythmdb_entry_unref (entry);
 		} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter));
 	}
 
@@ -371,6 +372,7 @@ get_query_model_contents (RhythmDBQueryM
 		RhythmDBEntry *entry;
 		entry = rhythmdb_query_model_iter_to_entry (model, &iter);
 		g_ptr_array_index (result, i++) = entry;
+		rhythmdb_entry_unref (entry);
 	} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter));
 
 	return result;
Index: shell/rb-play-order.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-play-order.c,v
retrieving revision 1.24
diff -p -u -r1.24 rb-play-order.c
--- shell/rb-play-order.c	17 Jul 2006 14:52:29 -0000	1.24
+++ shell/rb-play-order.c	21 Jul 2006 21:31:31 -0000
@@ -155,7 +155,8 @@ rb_play_order_init (RBPlayOrder *porder)
 }
 
 static GObject *
-rb_play_order_constructor (GType type, guint n_construct_properties,
+rb_play_order_constructor (GType type,
+			   guint n_construct_properties,
 			   GObjectConstructParam *construct_properties)
 {
 	RBPlayOrder *porder;
@@ -176,7 +177,11 @@ rb_play_order_finalize (GObject *object)
 
 	porder = RB_PLAY_ORDER (object);
 
-	if (porder->priv->query_model) {
+	if (porder->priv->playing_entry != NULL) {
+		rhythmdb_entry_unref (porder->priv->playing_entry);
+	}
+
+	if (porder->priv->query_model != NULL) {
 		g_signal_handlers_disconnect_by_func (G_OBJECT (porder->priv->query_model),
 						      G_CALLBACK (rb_play_order_entry_added_cb),
 						      porder);
@@ -209,6 +214,10 @@ rb_play_order_set_playing_entry_internal
 	old_entry = porder->priv->playing_entry;
 	porder->priv->playing_entry = entry;
 
+	if (porder->priv->playing_entry != NULL) {
+		rhythmdb_entry_ref (porder->priv->playing_entry);
+	}
+
 	if (RB_PLAY_ORDER_GET_CLASS (porder)->playing_entry_changed)
 		RB_PLAY_ORDER_GET_CLASS (porder)->playing_entry_changed (porder, old_entry, entry);
 
@@ -232,7 +241,7 @@ rb_play_order_set_property (GObject *obj
 		rb_play_order_set_player (porder, g_value_get_object (value));
 		break;
 	case PROP_PLAYING_ENTRY:
-		rb_play_order_set_playing_entry_internal (porder, g_value_dup_boxed (value));
+		rb_play_order_set_playing_entry_internal (porder, g_value_get_boxed (value));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -301,7 +310,8 @@ rb_play_order_get_orders (void)
  * Returns: #RBPlayOrder instance
  **/
 RBPlayOrder *
-rb_play_order_new (const char* porder_name, RBShellPlayer *player)
+rb_play_order_new (const char* porder_name,
+		   RBShellPlayer *player)
 {
 	int default_index = -1;
 	const RBPlayOrderDescription *orders = rb_play_order_get_orders ();
@@ -338,6 +348,8 @@ rb_play_order_new (const char* porder_na
 RBShellPlayer *
 rb_play_order_get_player (RBPlayOrder *porder)
 {
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
+
 	return porder->priv->player;
 }
 
@@ -352,6 +364,8 @@ rb_play_order_get_player (RBPlayOrder *p
 RBSource *
 rb_play_order_get_source (RBPlayOrder *porder)
 {
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
+
 	return porder->priv->source;
 }
 
@@ -366,6 +380,8 @@ rb_play_order_get_source (RBPlayOrder *p
 RhythmDB *
 rb_play_order_get_db (RBPlayOrder *porder)
 {
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
+
 	return porder->priv->db;
 }
 
@@ -380,6 +396,8 @@ rb_play_order_get_db (RBPlayOrder *porde
 RhythmDBQueryModel *
 rb_play_order_get_query_model (RBPlayOrder *porder)
 {
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
+
 	return porder->priv->query_model;
 }
 
@@ -392,6 +410,8 @@ rb_play_order_get_query_model (RBPlayOrd
 gboolean
 rb_play_order_player_is_playing (RBPlayOrder *porder)
 {
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), FALSE);
+
 	return (porder->priv->playing_entry != NULL);
 }
 
@@ -406,7 +426,9 @@ void
 rb_play_order_set_playing_entry (RBPlayOrder *porder,
 				 RhythmDBEntry *entry)
 {
-	g_object_set (G_OBJECT (porder), "playing-entry", entry, NULL);
+	g_return_if_fail (RB_IS_PLAY_ORDER (porder));
+
+	rb_play_order_set_playing_entry_internal (porder, entry);
 }
 
 /**
@@ -418,7 +440,16 @@ rb_play_order_set_playing_entry (RBPlayO
 RhythmDBEntry *
 rb_play_order_get_playing_entry (RBPlayOrder *porder)
 {
-	return porder->priv->playing_entry;
+	RhythmDBEntry *entry;
+
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
+
+	entry = porder->priv->playing_entry;
+	if (entry != NULL) {
+		rhythmdb_entry_ref (entry);
+	}
+
+	return entry;
 }
 
 /**
@@ -437,7 +468,7 @@ rb_play_order_playing_source_changed (RB
 {
 	RhythmDB *db = NULL;
 
-	g_return_if_fail (porder != NULL);
+	g_return_if_fail (RB_IS_PLAY_ORDER (porder));
 
 	g_object_get (porder->priv->player,
 		      "db", &db,
@@ -503,6 +534,8 @@ rb_play_order_query_model_changed (RBPla
 {
 	RhythmDBQueryModel *new_model = NULL;
 
+	g_return_if_fail (RB_IS_PLAY_ORDER (porder));
+
 	if (porder->priv->source)
 		g_object_get (porder->priv->source, "query-model", &new_model, NULL);
 
@@ -551,15 +584,24 @@ rb_play_order_query_model_changed (RBPla
  * #RhythmDBQueryModel.
  */
 static void
-rb_play_order_entry_added_cb (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, RBPlayOrder *porder)
+rb_play_order_entry_added_cb (GtkTreeModel *model,
+			      GtkTreePath *path,
+			      GtkTreeIter *iter,
+			      RBPlayOrder *porder)
 {
-	RhythmDBEntry *entry = rhythmdb_query_model_iter_to_entry(RHYTHMDB_QUERY_MODEL (model),
-								  iter);
+	RhythmDBEntry *entry;
+
+	entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model),
+						    iter);
 	if (RB_PLAY_ORDER_GET_CLASS (porder)->entry_added)
 		RB_PLAY_ORDER_GET_CLASS (porder)->entry_added (porder, entry);
 
 	if (!rhythmdb_query_model_has_pending_changes (RHYTHMDB_QUERY_MODEL (model)))
 		rb_play_order_update_have_next_previous (porder);
+
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
 }
 
 /**
@@ -577,7 +619,9 @@ rb_play_order_entry_added_cb (GtkTreeMod
  * signal is emitted.
  */
 static void
-rb_play_order_row_deleted_cb (GtkTreeModel *model, GtkTreePath *row, RBPlayOrder *porder)
+rb_play_order_row_deleted_cb (GtkTreeModel *model,
+			      GtkTreePath *row,
+			      RBPlayOrder *porder)
 {
 	RhythmDBEntry *entry;
 
@@ -597,19 +641,44 @@ rb_play_order_row_deleted_cb (GtkTreeMod
 static gboolean
 default_has_next (RBPlayOrder *porder)
 {
-	return rb_play_order_get_next (porder) != NULL;
+	RhythmDBEntry *entry;
+	gboolean res;
+
+	entry = rb_play_order_get_next (porder);
+
+	if (entry != NULL) {
+		res = TRUE;
+		rhythmdb_entry_unref (entry);
+	} else {
+		res = FALSE;
+	}
+
+	return res;
 }
 
 static gboolean
 default_has_previous (RBPlayOrder *porder)
 {
-	return rb_play_order_get_previous (porder) != NULL;
+	RhythmDBEntry *entry;
+	gboolean res;
+
+	entry = rb_play_order_get_previous (porder);
+
+	if (entry != NULL) {
+		res = TRUE;
+		rhythmdb_entry_unref (entry);
+	} else {
+		res = FALSE;
+	}
+
+	return res;
 }
 
 static gboolean
 sync_playing_entry_cb (RBPlayOrder *porder)
 {
 	RBShellPlayer *player = rb_play_order_get_player (porder);
+
 	if (porder->priv->playing_entry) {
 		rb_shell_player_play_entry (player,
 					    porder->priv->playing_entry,
@@ -630,7 +699,8 @@ sync_playing_entry_cb (RBPlayOrder *pord
 }
 
 static void
-default_playing_entry_removed (RBPlayOrder *porder, RhythmDBEntry *entry)
+default_playing_entry_removed (RBPlayOrder *porder,
+			       RhythmDBEntry *entry)
 {
 	RBShellPlayer *player = rb_play_order_get_player (porder);
 	RBSource *source = rb_shell_player_get_playing_source (player);
@@ -654,10 +724,13 @@ default_playing_entry_removed (RBPlayOrd
 
 				/* go to next song, in an idle function so that other handlers run first */
 				next_entry = rb_play_order_get_next (porder);
-				if (next_entry == entry)
+
+				if (next_entry == entry) {
+					rhythmdb_entry_unref (next_entry);
 					next_entry = NULL;
+				}
 
-				g_object_set (G_OBJECT (porder), "playing-entry", next_entry, NULL);
+				rb_play_order_set_playing_entry_internal (porder, next_entry);
 				if (porder->priv->sync_playing_entry_id == 0) {
 					porder->priv->sync_playing_entry_id =
 						g_idle_add_full (G_PRIORITY_HIGH_IDLE,
@@ -665,6 +738,11 @@ default_playing_entry_removed (RBPlayOrd
 								 porder,
 								 NULL);
 				}
+
+				if (next_entry != NULL) {
+					rhythmdb_entry_unref (next_entry);
+				}
+
 				break;
 			}
 		}
@@ -682,10 +760,11 @@ default_playing_entry_removed (RBPlayOrd
  * Returns: true if there is an entry after the current playing entry in the play order.
  */
 gboolean
-rb_play_order_has_next (RBPlayOrder* porder)
+rb_play_order_has_next (RBPlayOrder *porder)
 {
-	g_return_val_if_fail (porder != NULL, FALSE);
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), FALSE);
 	g_return_val_if_fail (RB_PLAY_ORDER_GET_CLASS (porder)->has_next != NULL, FALSE);
+
 	return RB_PLAY_ORDER_GET_CLASS (porder)->has_next (porder);
 }
 
@@ -698,8 +777,9 @@ rb_play_order_has_next (RBPlayOrder* por
 RhythmDBEntry *
 rb_play_order_get_next (RBPlayOrder *porder)
 {
-	g_return_val_if_fail (porder != NULL, NULL);
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
 	g_return_val_if_fail (RB_PLAY_ORDER_GET_CLASS (porder)->get_next != NULL, NULL);
+
 	return RB_PLAY_ORDER_GET_CLASS (porder)->get_next (porder);
 }
 
@@ -713,12 +793,19 @@ rb_play_order_get_next (RBPlayOrder *por
 void
 rb_play_order_go_next (RBPlayOrder *porder)
 {
-	g_return_if_fail (porder != NULL);
-	if (RB_PLAY_ORDER_GET_CLASS (porder)->go_next)
+	g_return_if_fail (RB_IS_PLAY_ORDER (porder));
+
+	if (RB_PLAY_ORDER_GET_CLASS (porder)->go_next) {
 		RB_PLAY_ORDER_GET_CLASS (porder)->go_next (porder);
-	else if (RB_PLAY_ORDER_GET_CLASS (porder)->get_next)
-		rb_play_order_set_playing_entry (porder,
-						 RB_PLAY_ORDER_GET_CLASS (porder)->get_next (porder));
+	} else if (RB_PLAY_ORDER_GET_CLASS (porder)->get_next) {
+		RhythmDBEntry *entry;
+
+		entry = RB_PLAY_ORDER_GET_CLASS (porder)->get_next (porder);
+		rb_play_order_set_playing_entry (porder, entry);
+		if (entry != NULL) {
+			rhythmdb_entry_unref (entry);
+		}
+	}
 }
 
 /**
@@ -729,10 +816,11 @@ rb_play_order_go_next (RBPlayOrder *pord
  * If not currently playing, returns false.
  */
 gboolean
-rb_play_order_has_previous (RBPlayOrder* porder)
+rb_play_order_has_previous (RBPlayOrder *porder)
 {
-	g_return_val_if_fail (porder != NULL, FALSE);
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), FALSE);
 	g_return_val_if_fail (RB_PLAY_ORDER_GET_CLASS (porder)->has_previous != NULL, FALSE);
+
 	return RB_PLAY_ORDER_GET_CLASS (porder)->has_previous (porder);
 }
 
@@ -745,8 +833,9 @@ rb_play_order_has_previous (RBPlayOrder*
 RhythmDBEntry *
 rb_play_order_get_previous (RBPlayOrder *porder)
 {
-	g_return_val_if_fail (porder != NULL, NULL);
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
 	g_return_val_if_fail (RB_PLAY_ORDER_GET_CLASS (porder)->get_previous != NULL, NULL);
+
 	return RB_PLAY_ORDER_GET_CLASS (porder)->get_previous (porder);
 }
 
@@ -759,12 +848,19 @@ rb_play_order_get_previous (RBPlayOrder 
 void
 rb_play_order_go_previous (RBPlayOrder *porder)
 {
-	g_return_if_fail (porder != NULL);
-	if (RB_PLAY_ORDER_GET_CLASS (porder)->go_previous)
+	g_return_if_fail (RB_IS_PLAY_ORDER (porder));
+
+	if (RB_PLAY_ORDER_GET_CLASS (porder)->go_previous) {
 		RB_PLAY_ORDER_GET_CLASS (porder)->go_previous (porder);
-	else if (RB_PLAY_ORDER_GET_CLASS (porder)->get_previous)
-		rb_play_order_set_playing_entry (porder,
-						 RB_PLAY_ORDER_GET_CLASS (porder)->get_previous (porder));
+	} else if (RB_PLAY_ORDER_GET_CLASS (porder)->get_previous) {
+		RhythmDBEntry *entry;
+
+		entry = RB_PLAY_ORDER_GET_CLASS (porder)->get_previous (porder);
+		rb_play_order_set_playing_entry (porder, entry);
+		if (entry != NULL) {
+			rhythmdb_entry_unref (entry);
+		}
+	}
 }
 
 /**
@@ -778,6 +874,8 @@ rb_play_order_go_previous (RBPlayOrder *
 gboolean
 rb_play_order_model_not_empty (RBPlayOrder *porder)
 {
+	g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), FALSE);
+
 	GtkTreeIter iter;
 	if (!porder->priv->query_model)
 		return FALSE;
@@ -795,8 +893,13 @@ rb_play_order_model_not_empty (RBPlayOrd
 void
 rb_play_order_update_have_next_previous (RBPlayOrder *porder)
 {
-	gboolean have_next = rb_play_order_has_next (porder);
-	gboolean have_previous = rb_play_order_has_previous (porder);
+	gboolean have_next;
+	gboolean have_previous;
+
+	g_return_if_fail (RB_IS_PLAY_ORDER (porder));
+
+	have_next = rb_play_order_has_next (porder);
+	have_previous = rb_play_order_has_previous (porder);
 
 	if ((have_next != porder->priv->have_next) ||
 	    (have_previous != porder->priv->have_previous)) {
Index: shell/rb-playlist-manager.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-playlist-manager.c,v
retrieving revision 1.111
diff -p -u -r1.111 rb-playlist-manager.c
--- shell/rb-playlist-manager.c	17 Jul 2006 14:52:29 -0000	1.111
+++ shell/rb-playlist-manager.c	21 Jul 2006 21:31:31 -0000
@@ -659,25 +659,29 @@ rb_playlist_manager_is_dirty (RBPlaylist
 		do {
 			RBSource *source;
 			gboolean local;
-			GValue v = {0,};
-			gtk_tree_model_get_value (model,
-						  &iter,
-						  RB_SOURCELIST_MODEL_COLUMN_SOURCE,
-						  &v);
-			source = g_value_get_pointer (&v);
-			if (RB_IS_PLAYLIST_SOURCE (source) == FALSE)
+
+			gtk_tree_model_get (model,
+					    &iter,
+					    RB_SOURCELIST_MODEL_COLUMN_SOURCE,
+					    &source,
+					    -1);
+			if (source == NULL) {
+				continue;
+			}
+			if (RB_IS_PLAYLIST_SOURCE (source) == FALSE) {
+				g_object_unref (source);
 				continue;
+			}
 
-			g_object_get (G_OBJECT (source),
+			g_object_get (source,
 				      "is-local", &local,
 				      NULL);
 			if (local) {
-				g_object_get (G_OBJECT (source),
-					      "dirty", &dirty,
-					      NULL);
+				g_object_get (source, "dirty", &dirty, NULL);
 				if (dirty)
 					break;
 			}
+			g_object_unref (source);
 		} while (gtk_tree_model_iter_next (model, &iter));
 	}
 
@@ -771,20 +775,26 @@ rb_playlist_manager_save_playlists (RBPl
 	if (gtk_tree_model_get_iter_first (model, &iter)) {
 		do {
 			RBSource *source;
-			GValue v = {0,};
 			gboolean local;
 
-			gtk_tree_model_get_value (model,
-						  &iter,
-						  RB_SOURCELIST_MODEL_COLUMN_SOURCE,
-						  &v);
-			source = g_value_get_pointer (&v);
-			if (RB_IS_PLAYLIST_SOURCE (source) == FALSE)
+			gtk_tree_model_get (model,
+					    &iter,
+					    RB_SOURCELIST_MODEL_COLUMN_SOURCE,
+					    &source,
+					    -1);
+			if (source == NULL) {
+				continue;
+			}
+			if (RB_IS_PLAYLIST_SOURCE (source) == FALSE) {
+				g_object_unref (source);
 				continue;
+			}
 
 			g_object_get (G_OBJECT (source), "is-local", &local, NULL);
 			if (local)
 				rb_playlist_source_save_to_xml (RB_PLAYLIST_SOURCE (source), root);
+
+			g_object_unref (source);
 		} while (gtk_tree_model_iter_next (model, &iter));
 	}
 
@@ -977,14 +987,21 @@ rb_playlist_manager_set_automatic_playli
 	GValueArray *limit_value = NULL;
 	const char *sort_key;
 	gint sort_direction;
+	GPtrArray *query;
 
 	rb_query_creator_get_limit (creator, &limit_type, &limit_value);
-	rb_query_creator_get_sort_order (creator, &sort_key, &sort_direction);
+	rb_query_creator_get_sort_order (creator,
+					 &sort_key,
+					 &sort_direction);
 
+	query = rb_query_creator_get_query (creator);
 	rb_auto_playlist_source_set_query (RB_AUTO_PLAYLIST_SOURCE (playlist),
-					   rb_query_creator_get_query (creator),
-					   limit_type, limit_value,
-					   sort_key, sort_direction);
+					   query,
+					   limit_type,
+					   limit_value,
+					   sort_key,
+					   sort_direction);
+	rhythmdb_query_free (query);
 }
 
 static void
@@ -1059,21 +1076,29 @@ rb_playlist_manager_cmd_edit_automatic_p
 		RhythmDBQueryModelLimitType limit_type;
 		GValueArray *limit_value = NULL;
 		GPtrArray *query;
-		const char *sort_key;
+		char *sort_key;
 		gint sort_direction;
 		EditAutoPlaylistData *data;
 
-		rb_auto_playlist_source_get_query (playlist, &query,
-						   &limit_type, &limit_value,
-						   &sort_key, &sort_direction);
+		sort_key = NULL;
+		rb_auto_playlist_source_get_query (playlist,
+						   &query,
+						   &limit_type,
+						   &limit_value,
+						   &sort_key,
+						   &sort_direction);
 
 		creator = RB_QUERY_CREATOR (rb_query_creator_new_from_query (mgr->priv->db,
 									     query,
-									     limit_type, limit_value,
-									     sort_key, sort_direction));
-		if (limit_value)
+									     limit_type,
+									     limit_value,
+									     sort_key,
+									     sort_direction));
+		if (limit_value != NULL) {
 			g_value_array_free (limit_value);
+		}
 		rhythmdb_query_free (query);
+		g_free (sort_key);
 
 		data = g_new0 (EditAutoPlaylistData, 1);
 		data->mgr = mgr;
@@ -1105,6 +1130,7 @@ _queue_track_cb (RhythmDBQueryModel *mod
 
 	entry = rhythmdb_query_model_iter_to_entry (model, iter);
 	rb_static_playlist_source_add_entry (queue_source, entry, -1);
+	rhythmdb_entry_unref (entry);
 
 	return FALSE;
 }
@@ -1397,24 +1423,29 @@ rb_playlist_manager_get_playlists (RBPla
 	if (gtk_tree_model_get_iter_first (model, &iter)) {
 		do {
 			RBSource *source;
-			GValue v = {0,};
 			gboolean local;
 
-			gtk_tree_model_get_value (model,
-						  &iter,
-						  RB_SOURCELIST_MODEL_COLUMN_SOURCE,
-						  &v);
-			source = g_value_get_pointer (&v);
-			if (RB_IS_PLAYLIST_SOURCE (source) == FALSE)
+			gtk_tree_model_get (model,
+					    &iter,
+					    RB_SOURCELIST_MODEL_COLUMN_SOURCE,
+					    &source,
+					    -1);
+			if (source == NULL) {
 				continue;
-			if (RB_IS_PLAY_QUEUE_SOURCE (source) == TRUE)
+			}
+			if (RB_IS_PLAYLIST_SOURCE (source) == FALSE
+			    || RB_IS_PLAY_QUEUE_SOURCE (source) == TRUE) {
+				g_object_unref (source);
 				continue;
+			}
+
 			g_object_get (G_OBJECT (source), "is-local", &local,
 				      NULL);
 			if (local) {
 				playlists = g_list_prepend (playlists, source);
 			}
 
+			g_object_unref (source);
 		} while (gtk_tree_model_iter_next (model, &iter));
 	}
 
@@ -1458,20 +1489,26 @@ rb_playlist_manager_get_playlist_names (
 	i = 0;
 	do {
 		RBSource *source;
-		GValue v = {0,};
 		char *source_name;
 
-		gtk_tree_model_get_value (model, &iter,
-					  RB_SOURCELIST_MODEL_COLUMN_SOURCE,
-					  &v);
-		source = g_value_get_pointer (&v);
-		if (!RB_IS_PLAYLIST_SOURCE (source))
+		gtk_tree_model_get (model, &iter,
+				    RB_SOURCELIST_MODEL_COLUMN_SOURCE,
+				    &source,
+				    -1);
+		if (source == NULL) {
 			continue;
-		if (RB_IS_PLAY_QUEUE_SOURCE (source))
+		}
+		if (RB_IS_PLAYLIST_SOURCE (source) == FALSE
+		    || RB_IS_PLAY_QUEUE_SOURCE (source) == TRUE) {
+			g_object_unref (source);
 			continue;
+		}
 
-		g_object_get (G_OBJECT (source), "name", &source_name, NULL);
+		g_object_get (source, "name", &source_name, NULL);
 		(*playlists)[i++] = source_name;
+
+		g_object_unref (source);
+
 	} while (gtk_tree_model_iter_next (model, &iter));
 
 	return TRUE;
@@ -1495,21 +1532,25 @@ _get_playlist_by_name (RBPlaylistManager
 
 	do {
 		RBSource *source;
-		GValue v = {0,};
 		char *source_name;
 
-		gtk_tree_model_get_value (model, &iter,
-					  RB_SOURCELIST_MODEL_COLUMN_SOURCE,
-					  &v);
-		source = g_value_get_pointer (&v);
-		if (!RB_IS_PLAYLIST_SOURCE (source))
+		gtk_tree_model_get (model, &iter,
+				    RB_SOURCELIST_MODEL_COLUMN_SOURCE,
+				    &source,
+				    -1);
+		if (source == NULL) {
+			continue;
+		}
+		if (RB_IS_PLAYLIST_SOURCE (source) == FALSE) {
+			g_object_unref (source);
 			continue;
+		}
 		g_object_get (G_OBJECT (source), "name", &source_name, NULL);
 		if (strcmp (name, source_name) == 0)
 			playlist = source;
 
 		g_free (source_name);
-
+		g_object_unref (source);
 	} while (gtk_tree_model_iter_next (model, &iter) && playlist == NULL);
 
 	return playlist;
Index: shell/rb-shell-clipboard.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-shell-clipboard.c,v
retrieving revision 1.49
diff -p -u -r1.49 rb-shell-clipboard.c
--- shell/rb-shell-clipboard.c	17 Jul 2006 14:52:29 -0000	1.49
+++ shell/rb-shell-clipboard.c	21 Jul 2006 21:31:31 -0000
@@ -881,7 +881,8 @@ add_playlist_to_menu (GtkTreeModel *mode
 		      GtkTreeIter *iter,
 		      RBShellClipboard *clipboard)
 {
-	RhythmDBEntryType entry_type, source_entry_type;
+	RhythmDBEntryType entry_type;
+	RhythmDBEntryType source_entry_type;
 	RBSource *source = NULL;
 	char *action_name;
 	GtkAction *action;
@@ -890,8 +891,14 @@ add_playlist_to_menu (GtkTreeModel *mode
 	gtk_tree_model_get (GTK_TREE_MODEL (model), iter,
 			    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &source, -1);
 
-	if (!RB_IS_STATIC_PLAYLIST_SOURCE (source))
+	if (source == NULL) {
 		return FALSE;
+	}
+
+	if (!RB_IS_STATIC_PLAYLIST_SOURCE (source)) {
+		g_object_unref (source);
+		return FALSE;
+	}
 
 	/* FIXME: allow add-to-playlist for iPods and the like,
 	 * based on the currently selected source
@@ -899,6 +906,7 @@ add_playlist_to_menu (GtkTreeModel *mode
 	entry_type = RHYTHMDB_ENTRY_TYPE_SONG;
 	g_object_get (source, "entry-type", &source_entry_type, NULL);
 	if (source_entry_type != entry_type) {
+		g_object_unref (source);
 		g_boxed_free (RHYTHMDB_TYPE_ENTRY_TYPE, source_entry_type);
 		return FALSE;
 	}
@@ -918,13 +926,13 @@ add_playlist_to_menu (GtkTreeModel *mode
 					 "activate", G_CALLBACK (rb_shell_clipboard_playlist_add_cb),
 					 clipboard, 0);
 
-		g_signal_connect_object (G_OBJECT (source),
+		g_signal_connect_object (source,
 					 "deleted", G_CALLBACK (rb_shell_clipboard_playlist_deleted_cb),
 					 clipboard, 0);
-		g_signal_connect_object (G_OBJECT (source),
+		g_signal_connect_object (source,
 					 "notify::name", G_CALLBACK (rb_shell_clipboard_playlist_renamed_cb),
 					 clipboard, 0);
-		g_signal_connect_object (G_OBJECT (source),
+		g_signal_connect_object (source,
 					 "notify::visibility", G_CALLBACK (rb_shell_clipboard_playlist_visible_cb),
 					 clipboard, 0);
 	}
@@ -938,6 +946,7 @@ add_playlist_to_menu (GtkTreeModel *mode
 
 	g_boxed_free (RHYTHMDB_TYPE_ENTRY_TYPE, source_entry_type);
 	g_free (action_name);
+	g_object_unref (source);
 
 	return FALSE;
 }
Index: shell/rb-shell-player.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-shell-player.c,v
retrieving revision 1.252
diff -p -u -r1.252 rb-shell-player.c
--- shell/rb-shell-player.c	17 Jul 2006 14:52:29 -0000	1.252
+++ shell/rb-shell-player.c	21 Jul 2006 21:31:32 -0000
@@ -124,7 +124,6 @@ static void rb_shell_player_sync_volume 
 static void rb_shell_player_sync_replaygain (RBShellPlayer *player,
                                              RhythmDBEntry *entry);
 static void tick_cb (RBPlayer *player, long elapsed, gpointer data);
-static void eos_cb (RBPlayer *player, gpointer data);
 static void error_cb (RBPlayer *player, const GError *err, gpointer data);
 static void buffering_cb (RBPlayer *player, guint progress, gpointer data);
 static void rb_shell_player_error (RBShellPlayer *player, gboolean async, const GError *err);
@@ -468,7 +467,8 @@ rb_shell_player_class_init (RBShellPlaye
 }
 
 static GObject *
-rb_shell_player_constructor (GType type, guint n_construct_properties,
+rb_shell_player_constructor (GType type,
+			     guint n_construct_properties,
 			     GObjectConstructParam *construct_properties)
 {
 	RBShellPlayer *player;
@@ -542,15 +542,139 @@ volume_pre_unmount_cb (GnomeVFSVolumeMon
 	}
 	g_free (uri_mount_point);
 	g_free (volume_mount_point);
+
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
 }
 
 static void
-reemit_playing_signal (RBShellPlayer *player, GParamSpec *pspec, gpointer data)
+reemit_playing_signal (RBShellPlayer *player,
+		       GParamSpec *pspec,
+		       gpointer data)
 {
 	g_signal_emit (player, rb_shell_player_signals[PLAYING_CHANGED], 0,
 		       rb_player_playing (player->priv->mmplayer));
 }
 
+static gboolean
+notify_playing_idle (RBShellPlayer *player)
+{
+	rb_debug ("emitting playing notification: %d", rb_player_playing (player->priv->mmplayer));
+	g_object_notify (G_OBJECT (player), "playing");
+	rb_shell_player_sync_buttons (player);
+	return FALSE;
+}
+
+static void
+rb_shell_player_open_playlist_url (RBShellPlayer *player,
+				   const char *location)
+{
+	GError *error = NULL;
+
+	rb_debug ("playing stream url %s", location);
+	rb_player_open (player->priv->mmplayer, location, &error);
+	if (error == NULL)
+		rb_player_play (player->priv->mmplayer, &error);
+
+	if (error) {
+		GDK_THREADS_ENTER ();
+		rb_shell_player_error (player, TRUE, error);
+		g_error_free (error);
+		GDK_THREADS_LEAVE ();
+	}
+	g_idle_add ((GSourceFunc) notify_playing_idle, player);
+}
+
+static void
+rb_shell_player_handle_eos_unlocked (RBShellPlayer *player)
+{
+	RhythmDBEntry *entry;
+	RBSource *source;
+
+	source = player->priv->current_playing_source;
+
+	/* nothing to do */
+	if (source == NULL) {
+		return;
+	}
+
+	entry = rb_shell_player_get_playing_entry (player);
+
+	switch (rb_source_handle_eos (source)) {
+	case RB_SOURCE_EOF_ERROR:
+		rb_error_dialog (NULL, _("Stream error"),
+				 _("Unexpected end of stream!"));
+		rb_shell_player_set_playing_source (player, NULL);
+		break;
+	case RB_SOURCE_EOF_STOP:
+		rb_shell_player_set_playing_source (player, NULL);
+		break;
+	case RB_SOURCE_EOF_RETRY: {
+		GTimeVal current;
+		gint diff;
+
+		g_get_current_time (&current);
+		diff = current.tv_sec - player->priv->last_retry.tv_sec;
+		player->priv->last_retry = current;
+
+		if (rb_source_try_playlist (source) &&
+		    !g_queue_is_empty (player->priv->playlist_urls)) {
+			char *location = g_queue_pop_head (player->priv->playlist_urls);
+			rb_debug ("trying next radio stream url: %s", location);
+
+			rb_shell_player_open_playlist_url (player, location);
+			g_free (location);
+			break;
+		}
+
+		if (diff < 4) {
+			rb_debug ("Last retry was less than 4 seconds ago...aborting retry playback");
+			rb_shell_player_set_playing_source (player, NULL);
+		} else {
+			rb_shell_player_play_entry (player, entry, NULL);
+		}
+	}
+		break;
+	case RB_SOURCE_EOF_NEXT:
+		{
+			GError *error = NULL;
+
+			if (!rb_shell_player_do_next (player, &error)) {
+				if (error->domain != RB_SHELL_PLAYER_ERROR ||
+				    error->code != RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST)
+					g_warning ("Unhandled error: %s", error->message);
+				else if (error->code == RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST)
+					rb_shell_player_set_playing_source (player, NULL);
+			}
+		}
+		break;
+	}
+
+	if (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_PLAYBACK_ERROR) == NULL) {
+		rb_debug ("updating play statistics");
+		rb_source_update_play_statistics (source,
+						  player->priv->db,
+						  entry);
+	}
+
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
+}
+
+static void
+rb_shell_player_handle_eos (RBShellPlayer *player)
+{
+	rb_debug ("handling eos!");
+
+	GDK_THREADS_ENTER ();
+
+	rb_shell_player_handle_eos_unlocked (player);
+
+	GDK_THREADS_LEAVE ();
+}
+
 static void
 rb_shell_player_init (RBShellPlayer *player)
 {
@@ -578,10 +702,10 @@ rb_shell_player_init (RBShellPlayer *pla
 				 G_CALLBACK (info_available_cb),
 				 player, 0);
 
-	g_signal_connect_object (G_OBJECT (player->priv->mmplayer),
+	g_signal_connect_object (player->priv->mmplayer,
 				 "eos",
-				 G_CALLBACK (eos_cb),
-				 player, 0);
+				 G_CALLBACK (rb_shell_player_handle_eos),
+				 player, G_CONNECT_SWAPPED);
 
 	g_signal_connect_object (G_OBJECT (player->priv->mmplayer),
 				 "tick",
@@ -915,7 +1039,8 @@ rb_shell_player_get_active_source (RBShe
 }
 
 RBShellPlayer *
-rb_shell_player_new (RhythmDB *db, GtkUIManager *mgr,
+rb_shell_player_new (RhythmDB *db,
+		     GtkUIManager *mgr,
 		     GtkActionGroup *actiongroup)
 {
 	return g_object_new (RB_TYPE_SHELL_PLAYER,
@@ -929,6 +1054,8 @@ RhythmDBEntry *
 rb_shell_player_get_playing_entry (RBShellPlayer *player)
 {
 	RBPlayOrder *porder;
+	RhythmDBEntry *entry;
+
 	if (player->priv->current_playing_source == NULL)
 		return NULL;
 
@@ -937,40 +1064,13 @@ rb_shell_player_get_playing_entry (RBShe
 	else
 		porder = player->priv->play_order;
 
-	if (!porder) {
+	if (porder == NULL) {
 		return NULL;
 	}
 
-	return rb_play_order_get_playing_entry (porder);
-}
+	entry = rb_play_order_get_playing_entry (porder);
 
-static gboolean
-notify_playing_idle (RBShellPlayer *player)
-{
-	rb_debug ("emitting playing notification: %d", rb_player_playing (player->priv->mmplayer));
-	g_object_notify (G_OBJECT (player), "playing");
-	rb_shell_player_sync_buttons (player);
-	return FALSE;
-}
-
-static void
-rb_shell_player_open_playlist_url (RBShellPlayer *player,
-				   const char *location)
-{
-	GError *error = NULL;
-
-	rb_debug ("playing stream url %s", location);
-	rb_player_open (player->priv->mmplayer, location, &error);
-	if (error == NULL)
-		rb_player_play (player->priv->mmplayer, &error);
-
-	if (error) {
-		GDK_THREADS_ENTER ();
-		rb_shell_player_error (player, TRUE, error);
-		g_error_free (error);
-		GDK_THREADS_LEAVE ();
-	}
-	g_idle_add ((GSourceFunc) notify_playing_idle, player);
+	return entry;
 }
 
 typedef struct {
@@ -979,8 +1079,10 @@ typedef struct {
 } OpenLocationThreadData;
 
 static void
-playlist_entry_cb (TotemPlParser *playlist, const char *uri,
-		   const char *title, const char *genre,
+playlist_entry_cb (TotemPlParser *playlist,
+		   const char *uri,
+		   const char *title,
+		   const char *genre,
 		   RBShellPlayer *player)
 {
 	rb_debug ("adding stream url %s", uri);
@@ -1089,7 +1191,9 @@ rb_shell_player_open_location (RBShellPl
 }
 
 static gboolean
-rb_shell_player_open_entry (RBShellPlayer *player, RhythmDBEntry *entry, GError **error)
+rb_shell_player_open_entry (RBShellPlayer *player,
+			    RhythmDBEntry *entry,
+			    GError **error)
 {
 	char *location;
 	gboolean result;
@@ -1115,7 +1219,8 @@ rb_shell_player_open_entry (RBShellPlaye
  * or already playing).
  **/
 gboolean
-rb_shell_player_play (RBShellPlayer *player, GError **error)
+rb_shell_player_play (RBShellPlayer *player,
+		      GError **error)
 {
 	RBEntryView *songs;
 
@@ -1158,7 +1263,7 @@ static gboolean
 do_next_idle (RBShellPlayer *player)
 {
 	/* use the EOS callback, so that EOF_SOURCE_ conditions are handled properly */
-	eos_cb (player->priv->mmplayer, player);
+	rb_shell_player_handle_eos (player);
 	player->priv->do_next_idle_id = 0;
 
 	return FALSE;
@@ -1229,8 +1334,10 @@ rb_shell_player_set_playing_entry (RBShe
 }
 
 static void
-gconf_play_order_changed (GConfClient *client,guint cnxn_id,
-			  GConfEntry *entry, RBShellPlayer *player)
+gconf_play_order_changed (GConfClient *client,
+			  guint cnxn_id,
+			  GConfEntry *entry,
+			  RBShellPlayer *player)
 {
 	rb_debug ("gconf play order changed");
 	player->priv->syncing_state = TRUE;
@@ -1271,7 +1378,8 @@ found:
 }
 
 static void
-rb_shell_player_set_play_order (RBShellPlayer *player, const gchar *new_val)
+rb_shell_player_set_play_order (RBShellPlayer *player,
+				const gchar *new_val)
 {
 	char *old_val;
 
@@ -1284,7 +1392,9 @@ rb_shell_player_set_play_order (RBShellP
 }
 
 void
-rb_shell_player_set_playback_state (RBShellPlayer *player, gboolean shuffle, gboolean repeat)
+rb_shell_player_set_playback_state (RBShellPlayer *player,
+				    gboolean shuffle,
+				    gboolean repeat)
 {
 	const char *neworder = state_to_play_order[shuffle ? 1 : 0][repeat ? 1 : 0];
 	rb_shell_player_set_play_order (player, neworder);
@@ -1293,25 +1403,26 @@ rb_shell_player_set_playback_state (RBSh
 static void
 rb_shell_player_sync_play_order (RBShellPlayer *player)
 {
-	char *new_play_order = eel_gconf_get_string (CONF_STATE_PLAY_ORDER);
+	char *new_play_order;
 	RhythmDBEntry *playing_entry = NULL;
 	RBSource *source;
 
-	if (!new_play_order) {
+	new_play_order = eel_gconf_get_string (CONF_STATE_PLAY_ORDER);
+	if (new_play_order == NULL) {
 		g_warning (CONF_STATE_PLAY_ORDER " gconf key not found!");
 		new_play_order = g_strdup ("linear");
 	}
 
 	if (player->priv->play_order != NULL) {
 		playing_entry = rb_play_order_get_playing_entry (player->priv->play_order);
-		g_signal_handlers_disconnect_by_func (G_OBJECT (player->priv->play_order),
+		g_signal_handlers_disconnect_by_func (player->priv->play_order,
 						      G_CALLBACK (rb_shell_player_play_order_update_cb),
 						      player);
 		g_object_unref (player->priv->play_order);
 	}
 
 	player->priv->play_order = rb_play_order_new (new_play_order, player);
-	g_signal_connect_object (G_OBJECT (player->priv->play_order),
+	g_signal_connect_object (player->priv->play_order,
 				 "have_next_previous_changed",
 				 G_CALLBACK (rb_shell_player_play_order_update_cb),
 				 player, 0);
@@ -1320,12 +1431,16 @@ rb_shell_player_sync_play_order (RBShell
 					      player);
 
 	source = player->priv->current_playing_source;
-	if (!source)
+	if (source == NULL) {
 		source = player->priv->selected_source;
+	}
 	rb_play_order_playing_source_changed (player->priv->play_order, source);
 
-	if (playing_entry)
+	if (playing_entry != NULL) {
 		rb_play_order_set_playing_entry (player->priv->play_order, playing_entry);
+		rhythmdb_entry_unref (playing_entry);
+	}
+
 	g_free (new_play_order);
 }
 
@@ -1341,10 +1456,13 @@ rb_shell_player_play_order_update_cb (RB
 	gboolean have_next = FALSE;
 	gboolean have_previous = FALSE;
 	GtkAction *action;
+	RhythmDBEntry *entry;
 
-	if (rb_shell_player_get_playing_entry (player)) {
+	entry = rb_shell_player_get_playing_entry (player);
+	if (entry != NULL) {
 		have_next = TRUE;
 		have_previous = TRUE;
+		rhythmdb_entry_unref (entry);
 	} else {
 		if (player->priv->current_playing_source &&
 		    (rb_source_handle_eos (player->priv->current_playing_source) == RB_SOURCE_EOF_NEXT)) {
@@ -1359,10 +1477,10 @@ rb_shell_player_play_order_update_cb (RB
 
 	action = gtk_action_group_get_action (player->priv->actiongroup,
 					      "ControlPrevious");
-	g_object_set (G_OBJECT (action), "sensitive", have_previous, NULL);
+	g_object_set (action, "sensitive", have_previous, NULL);
 	action = gtk_action_group_get_action (player->priv->actiongroup,
 					      "ControlNext");
-	g_object_set (G_OBJECT (action), "sensitive", have_next, NULL);
+	g_object_set (action, "sensitive", have_next, NULL);
 }
 
 static gboolean
@@ -1401,18 +1519,23 @@ rb_shell_player_jump_to_current (RBShell
 
 	songs = rb_source_get_entry_view (source);
 	entry = rb_shell_player_get_playing_entry (player);
-	if (songs) {
-		if (entry) {
+	if (songs != NULL) {
+		if (entry != NULL) {
 			rb_entry_view_scroll_to_entry (songs, entry);
 			rb_entry_view_select_entry (songs, entry);
 		} else {
 			rb_entry_view_select_none (songs);
 		}
 	}
+
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
 }
 
 static void
-swap_playing_source (RBShellPlayer *player, RBSource *new_source)
+swap_playing_source (RBShellPlayer *player,
+		     RBSource *new_source)
 {
 	if (player->priv->current_playing_source != NULL) {
 		RBEntryView *old_songs = rb_source_get_entry_view (player->priv->current_playing_source);
@@ -1430,9 +1553,10 @@ swap_playing_source (RBShellPlayer *play
 }
 
 gboolean
-rb_shell_player_do_previous (RBShellPlayer *player, GError **error)
+rb_shell_player_do_previous (RBShellPlayer *player,
+			     GError **error)
 {
-	RhythmDBEntry* entry = NULL;
+	RhythmDBEntry *entry = NULL;
 	RBSource *new_source;
 
 	if (player->priv->current_playing_source == NULL) {
@@ -1447,27 +1571,31 @@ rb_shell_player_do_previous (RBShellPlay
 
 	if (player->priv->queue_play_order) {
 		entry = rb_play_order_get_previous (player->priv->queue_play_order);
-		if (entry) {
+		if (entry != NULL) {
 			new_source = RB_SOURCE (player->priv->queue_source);
 			rb_play_order_go_previous (player->priv->queue_play_order);
 		}
 	}
 
-	if (!entry) {
+	if (entry == NULL) {
 		new_source = player->priv->source;
 		entry = rb_play_order_get_previous (player->priv->play_order);
 		if (entry)
 			rb_play_order_go_previous (player->priv->play_order);
 	}
 
-	if (entry) {
+	if (entry != NULL) {
 		rb_debug ("previous song found, doing previous");
 		if (new_source != player->priv->current_playing_source)
 			swap_playing_source (player, new_source);
 
-		if (!rb_shell_player_set_playing_entry (player, entry, FALSE, error))
+		if (!rb_shell_player_set_playing_entry (player, entry, FALSE, error)) {
+			rhythmdb_entry_unref (entry);
 			return FALSE;
+		}
+
 		rb_shell_player_jump_to_current (player);
+		rhythmdb_entry_unref (entry);
 	} else {
 		rb_debug ("no previous song found, signaling error");
 		g_set_error (error,
@@ -1482,7 +1610,8 @@ rb_shell_player_do_previous (RBShellPlay
 }
 
 gboolean
-rb_shell_player_do_next (RBShellPlayer *player, GError **error)
+rb_shell_player_do_next (RBShellPlayer *player,
+			 GError **error)
 {
 	RBSource *new_source = NULL;
 	RhythmDBEntry *entry = NULL;
@@ -1498,7 +1627,8 @@ rb_shell_player_do_next (RBShellPlayer *
 		 */
 		entry = rb_play_order_get_next (player->priv->queue_play_order);
 		rb_play_order_go_next (player->priv->queue_play_order);
-		if (entry) {
+
+		if (entry != NULL) {
 			new_source = RB_SOURCE (player->priv->queue_source);
 		} else {
 			/* If we haven't played anything from the playing source yet,
@@ -1516,15 +1646,19 @@ rb_shell_player_do_next (RBShellPlayer *
 	} else {
 		/* Advance the play order, and then let the queue override it. */
 		entry = rb_play_order_get_next (player->priv->play_order);
-		if (entry) {
+		if (entry != NULL) {
 			new_source = player->priv->source;
 			rb_play_order_go_next (player->priv->play_order);
 		}
 
 		if (player->priv->queue_play_order) {
 			RhythmDBEntry *queue_entry;
+
 			queue_entry = rb_play_order_get_next (player->priv->queue_play_order);
-			if (queue_entry) {
+			if (queue_entry != NULL) {
+				if (entry != NULL) {
+					rhythmdb_entry_unref (entry);
+				}
 				entry = queue_entry;
 				new_source = RB_SOURCE (player->priv->queue_source);
 				rb_play_order_go_next (player->priv->queue_play_order);
@@ -1533,7 +1667,7 @@ rb_shell_player_do_next (RBShellPlayer *
 	}
 
 	/* play the new entry */
-	if (entry) {
+	if (entry != NULL) {
 		/* if the entry view containing the playing entry changed, update it */
 		if (new_source != player->priv->current_playing_source)
 			swap_playing_source (player, new_source);
@@ -1551,13 +1685,19 @@ rb_shell_player_do_next (RBShellPlayer *
 		g_object_notify (G_OBJECT (player), "playing");
 		rv = FALSE;
 	}
+
 	g_idle_add ((GSourceFunc)rb_shell_player_jump_to_current_idle, player);
 
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
+
 	return rv;
 }
 
 static gboolean
-rb_shell_player_do_previous_or_seek (RBShellPlayer *player, GError **error)
+rb_shell_player_do_previous_or_seek (RBShellPlayer *player,
+				     GError **error)
 {
 	rb_debug ("previous");
 	/* If we're in the first 3 seconds go to the previous song,
@@ -1660,7 +1800,9 @@ rb_shell_player_cmd_play (GtkAction *act
 
 /* unused parameter can't be removed without breaking dbus interface compatibility */
 gboolean
-rb_shell_player_playpause (RBShellPlayer *player, gboolean unused, GError **error)
+rb_shell_player_playpause (RBShellPlayer *player,
+			   gboolean unused,
+			   GError **error)
 {
 	gboolean ret;
 	RBEntryView *songs;
@@ -1688,6 +1830,7 @@ rb_shell_player_playpause (RBShellPlayer
 		RhythmDBEntry *entry;
 		RBSource *new_source;
 		gboolean out_of_order = FALSE;
+
 		if (player->priv->source == NULL) {
 			/* no current stream, pull one in from the currently
 			 * selected source */
@@ -1748,11 +1891,16 @@ rb_shell_player_playpause (RBShellPlayer
 				ret = FALSE;
 			}
 		}
+
+		if (entry != NULL) {
+			rhythmdb_entry_unref (entry);
+		}
 	}
 
 	rb_shell_player_sync_with_source (player);
 	rb_shell_player_sync_buttons (player);
 	g_object_notify (G_OBJECT (player), "playing");
+
 	return ret;
 }
 
@@ -1776,9 +1924,11 @@ rb_shell_player_sync_control_state (RBSh
 }
 
 static void
-rb_shell_player_sync_volume (RBShellPlayer *player, gboolean notify)
+rb_shell_player_sync_volume (RBShellPlayer *player,
+			     gboolean notify)
 {
 	GtkAction *action;
+	RhythmDBEntry *entry;
 
 	if (player->priv->volume <= 0.0){
 		player->priv->volume = 0.0;
@@ -1799,8 +1949,12 @@ rb_shell_player_sync_volume (RBShellPlay
 
 	eel_gconf_set_float (CONF_STATE_VOLUME, player->priv->volume);
 
-	rb_shell_player_sync_replaygain (player,
-					 rb_shell_player_get_playing_entry (player));
+
+	entry = rb_shell_player_get_playing_entry (player);
+	rb_shell_player_sync_replaygain (player, entry);
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
 
 	if (notify)
 		g_object_notify (G_OBJECT (player), "volume");
@@ -1814,7 +1968,8 @@ rb_shell_player_toggle_mute (RBShellPlay
 }
 
 static void
-rb_shell_player_sync_replaygain (RBShellPlayer *player, RhythmDBEntry *entry)
+rb_shell_player_sync_replaygain (RBShellPlayer *player,
+				 RhythmDBEntry *entry)
 {
 	double entry_track_gain = 0;
 	double entry_track_peak = 0;
@@ -2028,6 +2183,10 @@ rb_shell_player_entry_activated_cb (RBEn
 	if (was_from_queue && prev_entry != NULL) {
 		rb_play_order_set_playing_entry (playa->priv->queue_play_order, NULL);
 	}
+
+	if (prev_entry != NULL) {
+		rhythmdb_entry_unref (prev_entry);
+	}
 }
 
 static void
@@ -2065,21 +2224,32 @@ rb_shell_player_property_row_activated_c
 		g_clear_error (&error);
 	}
 
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
+
  done:
 	g_object_unref (model);
 }
 
 static void
-rb_shell_player_entry_changed_cb (RhythmDB *db, RhythmDBEntry *entry,
-				       GSList *changes, RBShellPlayer *player)
+rb_shell_player_entry_changed_cb (RhythmDB *db,
+				  RhythmDBEntry *entry,
+				  GSList *changes,
+				  RBShellPlayer *player)
 {
 	GSList *t;
 	gboolean synced = FALSE;
 	const char *location;
-	RhythmDBEntry *playing_entry = rb_shell_player_get_playing_entry (player);
+	RhythmDBEntry *playing_entry;
+
+	playing_entry = rb_shell_player_get_playing_entry (player);
 
 	/* We try to update only if the changed entry is currently playing */
 	if (entry != playing_entry) {
+		if (playing_entry != NULL) {
+			rhythmdb_entry_unref (playing_entry);
+		}
 		return;
 	}
 
@@ -2119,6 +2289,10 @@ rb_shell_player_entry_changed_cb (Rhythm
 			break;
 		}
 	}
+
+	if (playing_entry != NULL) {
+		rhythmdb_entry_unref (playing_entry);
+	}
 }
 
 static void
@@ -2163,6 +2337,10 @@ rb_shell_player_sync_with_source (RBShel
 
 	rb_header_set_playing_entry (player->priv->header_widget, entry);
 	rb_header_sync (player->priv->header_widget);
+
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
 }
 
 static void
@@ -2174,8 +2352,10 @@ rb_shell_player_sync_buttons (RBShellPla
 	gboolean playing_from_queue;
 	RBEntryView *view;
 	int entry_view_state;
+	RhythmDBEntry *entry;
 
-	if (rb_shell_player_get_playing_entry (player)) {
+	entry = rb_shell_player_get_playing_entry (player);
+	if (entry != NULL) {
 		source = player->priv->current_playing_source;
 		entry_view_state = rb_player_playing (player->priv->mmplayer) ?
 			RB_ENTRY_VIEW_PLAYING : RB_ENTRY_VIEW_PAUSED;
@@ -2184,8 +2364,7 @@ rb_shell_player_sync_buttons (RBShellPla
 		entry_view_state = RB_ENTRY_VIEW_NOT_PLAYING;
 	}
 
-	source = rb_shell_player_get_playing_entry (player) == NULL ?
-		 player->priv->selected_source : player->priv->current_playing_source;
+	source = (entry == NULL) ? player->priv->selected_source : player->priv->current_playing_source;
 
 	playing_from_queue = (source == RB_SOURCE (player->priv->queue_source));
 
@@ -2194,16 +2373,18 @@ rb_shell_player_sync_buttons (RBShellPla
         not_small = !eel_gconf_get_boolean (CONF_UI_SMALL_DISPLAY);
 	action = gtk_action_group_get_action (player->priv->actiongroup,
 					      "ViewJumpToPlaying");
-	g_object_set (G_OBJECT (action),
-		      "sensitive",
-		      rb_shell_player_get_playing_entry (player) != NULL
-		      && not_small, NULL);
+	g_object_set (action,
+		      "sensitive", entry != NULL && not_small, NULL);
 
-	if (source) {
+	if (source != NULL) {
 		view = rb_source_get_entry_view (source);
 		if (view)
 			rb_entry_view_set_state (view, entry_view_state);
 	}
+
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
 }
 
 void
@@ -2357,7 +2538,8 @@ rb_shell_player_stop (RBShellPlayer *pla
  **/
 
 gboolean
-rb_shell_player_pause (RBShellPlayer *player, GError **error)
+rb_shell_player_pause (RBShellPlayer *player,
+		       GError **error)
 {
 	if (rb_player_playing (player->priv->mmplayer))
 		return rb_shell_player_playpause (player, FALSE, error);
@@ -2437,6 +2619,7 @@ long
 rb_shell_player_get_playing_song_duration (RBShellPlayer *player)
 {
 	RhythmDBEntry *current_entry;
+	long val;
 
 	g_return_val_if_fail (RB_IS_SHELL_PLAYER (player), -1);
 
@@ -2447,7 +2630,11 @@ rb_shell_player_get_playing_song_duratio
 		return -1;
 	}
 
-	return rhythmdb_entry_get_ulong (current_entry, RHYTHMDB_PROP_DURATION);
+	val = rhythmdb_entry_get_ulong (current_entry, RHYTHMDB_PROP_DURATION);
+
+	rhythmdb_entry_unref (current_entry);
+
+	return val;
 }
 
 static void
@@ -2465,81 +2652,9 @@ rb_shell_player_sync_with_selected_sourc
 }
 
 static void
-eos_cb (RBPlayer *mmplayer, gpointer data)
-{
- 	RBShellPlayer *player = RB_SHELL_PLAYER (data);
-	rb_debug ("eos!");
-
-	GDK_THREADS_ENTER ();
-
-	if (player->priv->current_playing_source != NULL) {
-		RhythmDBEntry *entry = rb_shell_player_get_playing_entry (player);
-		RBSource *source = player->priv->current_playing_source;
-
-		switch (rb_source_handle_eos (source))
-		{
-		case RB_SOURCE_EOF_ERROR:
-			rb_error_dialog (NULL, _("Stream error"),
-					 _("Unexpected end of stream!"));
-			rb_shell_player_set_playing_source (player, NULL);
-			break;
-		case RB_SOURCE_EOF_STOP:
-			rb_shell_player_set_playing_source (player, NULL);
-			break;
-		case RB_SOURCE_EOF_RETRY: {
-			GTimeVal current;
-			gint diff;
-
-			g_get_current_time (&current);
-			diff = current.tv_sec - player->priv->last_retry.tv_sec;
-			player->priv->last_retry = current;
-
-			if (rb_source_try_playlist (player->priv->current_playing_source) &&
-			    !g_queue_is_empty (player->priv->playlist_urls)) {
-				char *location = g_queue_pop_head (player->priv->playlist_urls);
-				rb_debug ("trying next radio stream url: %s", location);
-
-				rb_shell_player_open_playlist_url (player, location);
-				g_free (location);
-				break;
-			}
-
-			if (diff < 4) {
-				rb_debug ("Last retry was less than 4 seconds ago...aborting retry playback");
-				rb_shell_player_set_playing_source (player, NULL);
-			} else {
-				rb_shell_player_play_entry (player, entry, NULL);
-			}
-		}
-			break;
-		case RB_SOURCE_EOF_NEXT:
-			{
-				GError *error = NULL;
-
-				if (!rb_shell_player_do_next (player, &error)) {
-					if (error->domain != RB_SHELL_PLAYER_ERROR ||
-					    error->code != RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST)
-						g_warning ("eos_cb: Unhandled error: %s", error->message);
-					else if (error->code == RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST)
-						rb_shell_player_set_playing_source (player, NULL);
-				}
-			}
-			break;
-		}
-
-		if (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_PLAYBACK_ERROR) == NULL) {
-			rb_debug ("updating play statistics");
-			rb_source_update_play_statistics (source,
-							  player->priv->db,
-							  entry);
-		}
-	}
-
-	GDK_THREADS_LEAVE ();
-}
-
-static void
-rb_shell_player_error (RBShellPlayer *player, gboolean async, const GError *err)
+rb_shell_player_error (RBShellPlayer *player,
+		       gboolean async,
+		       const GError *err)
 {
 	RhythmDBEntry *entry;
 
@@ -2569,10 +2684,16 @@ rb_shell_player_error (RBShellPlayer *pl
 	}
 
 	player->priv->handling_error = FALSE;
+
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
 }
 
 static void
-error_cb (RBPlayer *mmplayer, const GError *err, gpointer data)
+error_cb (RBPlayer *mmplayer,
+	  const GError *err,
+	  gpointer data)
 {
 	RBShellPlayer *player = RB_SHELL_PLAYER (data);
 
@@ -2593,7 +2714,9 @@ error_cb (RBPlayer *mmplayer, const GErr
 }
 
 static void
-tick_cb (RBPlayer *mmplayer, long elapsed, gpointer data)
+tick_cb (RBPlayer *mmplayer,
+	 long elapsed,
+	 gpointer data)
 {
  	RBShellPlayer *player = RB_SHELL_PLAYER (data);
 
@@ -2747,11 +2870,17 @@ info_available_cb (RBPlayer *mmplayer,
 	}
 
  out_unlock:
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
+
 	GDK_THREADS_LEAVE ();
 }
 
 static void
-buffering_cb (RBPlayer *mmplayer, guint progress, gpointer data)
+buffering_cb (RBPlayer *mmplayer,
+	      guint progress,
+	      gpointer data)
 {
  	RBShellPlayer *player = RB_SHELL_PLAYER (data);
 
@@ -2774,12 +2903,17 @@ rb_shell_player_get_playing_path (RBShel
 		*path = NULL;
 	}
 
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
+
 	return TRUE;
 }
 
 #ifdef HAVE_MMKEYS
 static void
-grab_mmkey (int key_code, GdkWindow *root)
+grab_mmkey (int key_code,
+	    GdkWindow *root)
 {
 	gdk_error_trap_push ();
 
@@ -2823,7 +2957,9 @@ grab_mmkey (int key_code, GdkWindow *roo
 }
 
 static GdkFilterReturn
-filter_mmkeys (GdkXEvent *xevent, GdkEvent *event, gpointer data)
+filter_mmkeys (GdkXEvent *xevent,
+	       GdkEvent *event,
+	       gpointer data)
 {
 	XEvent *xev;
 	XKeyEvent *key;
Index: shell/rb-shell.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-shell.c,v
retrieving revision 1.464
diff -p -u -r1.464 rb-shell.c
--- shell/rb-shell.c	17 Jul 2006 14:52:29 -0000	1.464
+++ shell/rb-shell.c	21 Jul 2006 21:31:32 -0000
@@ -1845,6 +1845,7 @@ rb_shell_playing_from_queue_cb (RBShellP
 		rb_entry_view_set_state (songs, from_queue ? RB_ENTRY_VIEW_PLAYING : RB_ENTRY_VIEW_NOT_PLAYING);
 		rb_sourcelist_set_playing_source (RB_SOURCELIST (shell->priv->sourcelist),
 						  rb_shell_player_get_active_source (shell->priv->player_shell));
+		rhythmdb_entry_unref (entry);
 	}
 }
 
@@ -2763,14 +2764,17 @@ rb_shell_play_entry (RBShell *shell,
 static void
 rb_shell_jump_to_current (RBShell *shell)
 {
-	RBSource *source = rb_shell_player_get_playing_source (shell->priv->player_shell);
+	RBSource *source;
 	RhythmDBEntry *playing;
 
+	source = rb_shell_player_get_playing_source (shell->priv->player_shell);
+
 	g_return_if_fail (source != NULL);
 
 	playing = rb_shell_player_get_playing_entry (shell->priv->player_shell);
 
 	rb_shell_jump_to_entry_with_source (shell, source, playing);
+	rhythmdb_entry_unref (playing);
 }
 
 static gboolean
Index: sources/rb-auto-playlist-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-auto-playlist-source.c,v
retrieving revision 1.27
diff -p -u -r1.27 rb-auto-playlist-source.c
--- sources/rb-auto-playlist-source.c	17 Jul 2006 14:52:42 -0000	1.27
+++ sources/rb-auto-playlist-source.c	21 Jul 2006 21:31:33 -0000
@@ -165,14 +165,17 @@ rb_auto_playlist_source_finalize (GObjec
 		g_object_unref (priv->action_group);
 	}
 
-	if (priv->cached_all_query)
+	if (priv->cached_all_query) {
 		g_object_unref (G_OBJECT (priv->cached_all_query));
+	}
 
-	if (priv->query)
+	if (priv->query) {
 		rhythmdb_query_free (priv->query);
+	}
 
-	if (priv->limit_value)
+	if (priv->limit_value) {
 		g_value_array_free (priv->limit_value);
+	}
 
 	g_free (priv->search_text);
 
@@ -489,7 +492,7 @@ impl_receive_drag (RBSource *asource, Gt
 
 	g_strfreev (names);
 
-	if (subquery) {
+	if (subquery != NULL) {
 		RhythmDBEntryType qtype;
 		GPtrArray *query;
 
@@ -507,6 +510,9 @@ impl_receive_drag (RBSource *asource, Gt
 		rb_auto_playlist_source_set_query (RB_AUTO_PLAYLIST_SOURCE (source), query,
 						   RHYTHMDB_QUERY_MODEL_LIMIT_NONE, NULL,
 						   NULL, 0);
+
+		rhythmdb_query_free (subquery);
+		rhythmdb_query_free (query);
 	}
 
 	g_object_unref (db);
@@ -539,21 +545,25 @@ _save_write_uint64 (xmlNodePtr node, GVa
 }
 
 static void
-impl_save_contents_to_xml (RBPlaylistSource *psource, xmlNodePtr node)
+impl_save_contents_to_xml (RBPlaylistSource *psource,
+			   xmlNodePtr node)
 {
 	GPtrArray *query;
 	RhythmDBQueryModelLimitType limit_type;
 	GValueArray *limit_value = NULL;
-	const gchar *sort_key;
+	char *sort_key;
 	gint sort_direction;
 	RBAutoPlaylistSource *source = RB_AUTO_PLAYLIST_SOURCE (psource);
 
 	xmlSetProp (node, RB_PLAYLIST_TYPE, RB_PLAYLIST_AUTOMATIC);
 
+	sort_key = NULL;
 	rb_auto_playlist_source_get_query (source,
-					    &query,
-					    &limit_type, &limit_value,
-					    &sort_key, &sort_direction);
+					   &query,
+					   &limit_type,
+					   &limit_value,
+					   &sort_key,
+					   &sort_direction);
 
 	switch (limit_type) {
 	case RHYTHMDB_QUERY_MODEL_LIMIT_NONE:
@@ -576,16 +586,18 @@ impl_save_contents_to_xml (RBPlaylistSou
 	}
 
 	if (sort_key && *sort_key) {
-		gchar *temp_str;
+		char *temp_str;
 
 		xmlSetProp (node, RB_PLAYLIST_SORT_KEY, BAD_CAST sort_key);
 		temp_str = g_strdup_printf ("%d", sort_direction);
 		xmlSetProp (node, RB_PLAYLIST_SORT_DIRECTION, BAD_CAST temp_str);
+
 		g_free (temp_str);
 	}
 
 	rhythmdb_query_serialize (rb_playlist_source_get_db (psource), query, node);
 	rhythmdb_query_free (query);
+	g_free (sort_key);
 }
 
 static void
@@ -672,12 +684,17 @@ rb_auto_playlist_source_set_query (RBAut
 	RBEntryView *songs = rb_source_get_entry_view (RB_SOURCE (source));
 
 	priv->query_resetting = TRUE;
-	if (priv->query)
+	if (priv->query) {
 		rhythmdb_query_free (priv->query);
-	if (priv->cached_all_query)
+	}
+
+	if (priv->cached_all_query) {
 		g_object_unref (G_OBJECT (priv->cached_all_query));
-	if (priv->limit_value)
+	}
+
+	if (priv->limit_value) {
 		g_value_array_free (priv->limit_value);
+	}
 
 	/* playlists that aren't limited, with a particular sort order, are user-orderable */
 	rb_entry_view_set_columns_clickable (songs, (limit_type == RHYTHMDB_QUERY_MODEL_LIMIT_NONE));
@@ -688,28 +705,33 @@ rb_auto_playlist_source_set_query (RBAut
 	priv->limit_value = limit_value ? g_value_array_copy (limit_value) : NULL;
 
 	priv->cached_all_query = g_object_new (RHYTHMDB_TYPE_QUERY_MODEL,
-					      "db", db,
-					      "limit-type", priv->limit_type,
-					      "limit-value", priv->limit_value,
-					      NULL);
+					       "db", db,
+					       "limit-type", priv->limit_type,
+					       "limit-value", priv->limit_value,
+					       NULL);
 	rb_library_browser_set_model (priv->browser, priv->cached_all_query, TRUE);
 	rhythmdb_do_full_query_async_parsed (db,
 					     RHYTHMDB_QUERY_RESULTS (priv->cached_all_query),
-					     query);
+					     priv->query);
 
 	priv->query_resetting = FALSE;
 }
 
 void
 rb_auto_playlist_source_get_query (RBAutoPlaylistSource *source,
-				    GPtrArray **query,
-				    RhythmDBQueryModelLimitType *limit_type,
-				    GValueArray **limit_value,
-				    const char **sort_key,
-				    gint *sort_direction)
+				   GPtrArray **query,
+				   RhythmDBQueryModelLimitType *limit_type,
+				   GValueArray **limit_value,
+				   char **sort_key,
+				   gint *sort_direction)
 {
-	RBAutoPlaylistSourcePrivate *priv = RB_AUTO_PLAYLIST_SOURCE_GET_PRIVATE (source);
-	RBEntryView *songs = rb_source_get_entry_view (RB_SOURCE (source));
+	RBAutoPlaylistSourcePrivate *priv;
+	RBEntryView *songs;
+
+ 	g_return_if_fail (RB_IS_AUTO_PLAYLIST_SOURCE (source));
+
+	priv = RB_AUTO_PLAYLIST_SOURCE_GET_PRIVATE (source);
+	songs = rb_source_get_entry_view (RB_SOURCE (source));
 
 	*query = rhythmdb_query_copy (priv->query);
 	*limit_type = priv->limit_type;
Index: sources/rb-auto-playlist-source.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-auto-playlist-source.h,v
retrieving revision 1.5
diff -p -u -r1.5 rb-auto-playlist-source.h
--- sources/rb-auto-playlist-source.h	17 Jul 2006 14:52:42 -0000	1.5
+++ sources/rb-auto-playlist-source.h	21 Jul 2006 21:31:33 -0000
@@ -66,7 +66,7 @@ void		rb_auto_playlist_source_get_query	
 							 GPtrArray **query,
 							 RhythmDBQueryModelLimitType *limit_type,
 							 GValueArray **limit_value,
-							 const char **sort_key,
+							 char **sort_key,
 							 gint *sort_order);
 
 G_END_DECLS
Index: sources/rb-browser-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-browser-source.c,v
retrieving revision 1.15
diff -p -u -r1.15 rb-browser-source.c
--- sources/rb-browser-source.c	17 Jul 2006 14:52:43 -0000	1.15
+++ sources/rb-browser-source.c	21 Jul 2006 21:31:33 -0000
@@ -21,7 +21,8 @@
  *
  */
 
-#include <config.h>
+#include "config.h"
+
 #include <string.h>
 
 #include <gtk/gtk.h>
@@ -893,5 +894,6 @@ rb_browser_source_do_query (RBBrowserSou
 						     query);
 		g_object_unref (G_OBJECT (query_model));
 	}
+
 	rhythmdb_query_free (query);
 }
Index: sources/rb-import-errors-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-import-errors-source.c,v
retrieving revision 1.9
diff -p -u -r1.9 rb-import-errors-source.c
--- sources/rb-import-errors-source.c	17 Jul 2006 14:52:43 -0000	1.9
+++ sources/rb-import-errors-source.c	21 Jul 2006 21:31:33 -0000
@@ -133,7 +133,7 @@ rb_import_errors_source_constructor (GTy
 	model = rhythmdb_query_model_new (source->priv->db, query,
 					  (GCompareDataFunc) rhythmdb_query_model_string_sort_func,
 					  GUINT_TO_POINTER (RHYTHMDB_PROP_LOCATION), NULL, FALSE);
-	g_ptr_array_free (query, TRUE);
+	rhythmdb_query_free (query);
 
 	/* set up entry view */
 	source->priv->view = rb_entry_view_new (source->priv->db, shell_player,
Index: sources/rb-iradio-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-iradio-source.c,v
retrieving revision 1.126
diff -p -u -r1.126 rb-iradio-source.c
--- sources/rb-iradio-source.c	17 Jul 2006 14:52:43 -0000	1.126
+++ sources/rb-iradio-source.c	21 Jul 2006 21:31:33 -0000
@@ -743,25 +743,28 @@ rb_iradio_source_do_query (RBIRadioSourc
 	genre_query_model = rhythmdb_query_model_new_empty (source->priv->db);
 
 	if (source->priv->search_text) {
-		GPtrArray *subquery = rhythmdb_query_parse (source->priv->db,
-							    RHYTHMDB_QUERY_PROP_LIKE,
-							    RHYTHMDB_PROP_GENRE_FOLDED,
-							    source->priv->search_text,
-							    RHYTHMDB_QUERY_DISJUNCTION,
-							    RHYTHMDB_QUERY_PROP_LIKE,
-							    RHYTHMDB_PROP_TITLE_FOLDED,
-							    source->priv->search_text,
-							    RHYTHMDB_QUERY_END);
+		GPtrArray *subquery;
+		subquery = rhythmdb_query_parse (source->priv->db,
+						 RHYTHMDB_QUERY_PROP_LIKE,
+						 RHYTHMDB_PROP_GENRE_FOLDED,
+						 source->priv->search_text,
+						 RHYTHMDB_QUERY_DISJUNCTION,
+						 RHYTHMDB_QUERY_PROP_LIKE,
+						 RHYTHMDB_PROP_TITLE_FOLDED,
+						 source->priv->search_text,
+						 RHYTHMDB_QUERY_END);
 		rb_debug ("searching for \"%s\"", source->priv->search_text);
 		rhythmdb_query_append (source->priv->db,
 				       query,
 				       RHYTHMDB_QUERY_SUBQUERY,
 				       subquery,
 				       RHYTHMDB_QUERY_END);
+
+		rhythmdb_query_free (subquery);
 	}
 
 	genre_model = rb_property_view_get_model (source->priv->genres);
-	g_object_set (G_OBJECT (genre_model), "query-model", genre_query_model, NULL);
+	g_object_set (genre_model, "query-model", genre_query_model, NULL);
 
 	rhythmdb_do_full_query_parsed (source->priv->db,
 				       RHYTHMDB_QUERY_RESULTS (genre_query_model),
@@ -784,7 +787,7 @@ rb_iradio_source_do_query (RBIRadioSourc
 		rb_property_view_set_selection (source->priv->genres, sel);
 		g_list_free (sel);
 	}
-	g_object_unref (G_OBJECT (genre_model));
+	g_object_unref (genre_model);
 
 	/* if a genre is selected, construct a new query for it, and create
 	 * a new model based on the search box query model.  otherwise, just
@@ -804,6 +807,7 @@ rb_iradio_source_do_query (RBIRadioSourc
 			      "query", query,
 			      "base-model", genre_query_model,
 			      NULL);
+
 		rhythmdb_query_free (query);
 		query = NULL;
 	} else {
Index: sources/rb-library-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-library-source.c,v
retrieving revision 1.179
diff -p -u -r1.179 rb-library-source.c
--- sources/rb-library-source.c	17 Jul 2006 14:52:43 -0000	1.179
+++ sources/rb-library-source.c	21 Jul 2006 21:31:33 -0000
@@ -21,7 +21,8 @@
  *
  */
 
-#include <config.h>
+#include "config.h"
+
 #include <string.h>
 
 #include <gtk/gtk.h>
@@ -813,7 +814,8 @@ sanitize_path (const char *str)
  * %tS -- track artist sortname (lowercase)
  */
 static char *
-filepath_parse_pattern (const char *pattern, RhythmDBEntry *entry)
+filepath_parse_pattern (const char *pattern,
+			RhythmDBEntry *entry)
 {
 	/* p is the pattern iterator, i is a general purpose iterator */
 	const char *p;
Index: sources/rb-missing-files-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-missing-files-source.c,v
retrieving revision 1.8
diff -p -u -r1.8 rb-missing-files-source.c
--- sources/rb-missing-files-source.c	17 Jul 2006 14:52:43 -0000	1.8
+++ sources/rb-missing-files-source.c	21 Jul 2006 21:31:33 -0000
@@ -172,7 +172,8 @@ rb_missing_files_source_constructor (GTy
 				      RHYTHMDB_QUERY_END);
 	model = rhythmdb_query_model_new (source->priv->db, query,
 					  NULL, NULL, NULL, FALSE);
-	g_ptr_array_free (query, TRUE);
+
+	rhythmdb_query_free (query);
 
 	g_object_set (G_OBJECT (model), "show-hidden", TRUE, NULL);
 
Index: sources/rb-play-queue-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-play-queue-source.c,v
retrieving revision 1.17
diff -p -u -r1.17 rb-play-queue-source.c
--- sources/rb-play-queue-source.c	17 Jul 2006 14:52:43 -0000	1.17
+++ sources/rb-play-queue-source.c	21 Jul 2006 21:31:33 -0000
@@ -283,8 +283,11 @@ rb_play_queue_source_clear_queue (RBPlay
 	model = rb_playlist_source_get_query_model (RB_PLAYLIST_SOURCE (source));
 	while (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) {
 		entry = rhythmdb_query_model_iter_to_entry (model, &iter);
-		if (entry)
+
+		if (entry != NULL) {
 			rhythmdb_query_model_remove_entry (model, entry);
+			rhythmdb_entry_unref (entry);
+		}
 	}
 }
 
@@ -310,22 +313,25 @@ rb_play_queue_source_track_info_cell_dat
 						RBPlaylistSource *source)
 {
 	RhythmDBEntry *entry;
-	gtk_tree_model_get (tree_model, iter, 0, &entry, -1);
 	const char *title;
 	const char *artist;
 	const char *album;
 	char *markup;
 
+	gtk_tree_model_get (tree_model, iter, 0, &entry, -1);
+
 	title = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE);
 	artist = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST);
 	album = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM);
 
 	/* Translators: format is "<title> from <album> by <artist>" */
-	markup = g_markup_printf_escaped("%s\n<span size=\"smaller\">%s <i>%s</i>\n%s <i>%s</i></span>",
-				         title, _("from"), album, _("by"), artist);
+	markup = g_markup_printf_escaped ("%s\n<span size=\"smaller\">%s <i>%s</i>\n%s <i>%s</i></span>",
+					  title, _("from"), album, _("by"), artist);
 
 	g_object_set (G_OBJECT (renderer), "markup", markup, NULL);
+
 	g_free (markup);
+	rhythmdb_entry_unref (entry);
 }
 
 static void
Index: sources/rb-playlist-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-playlist-source.c,v
retrieving revision 1.126
diff -p -u -r1.126 rb-playlist-source.c
--- sources/rb-playlist-source.c	17 Jul 2006 14:52:43 -0000	1.126
+++ sources/rb-playlist-source.c	21 Jul 2006 21:31:33 -0000
@@ -337,14 +337,13 @@ rb_playlist_source_finalize (GObject *ob
 
 static void
 rb_playlist_source_set_property (GObject *object,
-			      guint prop_id,
-			      const GValue *value,
-			      GParamSpec *pspec)
+				 guint prop_id,
+				 const GValue *value,
+				 GParamSpec *pspec)
 {
 	RBPlaylistSource *source = RB_PLAYLIST_SOURCE (object);
 
-	switch (prop_id)
-	{
+	switch (prop_id) {
 	case PROP_LOCAL:
 		source->priv->is_local = g_value_get_boolean (value);
 		break;
@@ -359,14 +358,13 @@ rb_playlist_source_set_property (GObject
 
 static void
 rb_playlist_source_get_property (GObject *object,
-			      guint prop_id,
-			      GValue *value,
-			      GParamSpec *pspec)
+				 guint prop_id,
+				 GValue *value,
+				 GParamSpec *pspec)
 {
 	RBPlaylistSource *source = RB_PLAYLIST_SOURCE (object);
 
-	switch (prop_id)
-	{
+	switch (prop_id) {
 	case PROP_DB:
 		g_value_set_object (value, source->priv->db);
 		break;
@@ -478,8 +476,16 @@ playlist_iter_func (GtkTreeModel *model,
 
 	gtk_tree_model_get (model, iter, 0, &entry, -1);
 
-	*uri = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_LOCATION);
-	*title = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_TITLE);
+	if (uri != NULL) {
+		*uri = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_LOCATION);
+	}
+	if (title != NULL) {
+		*title = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_TITLE);
+	}
+
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
 }
 #else
 static void
@@ -494,9 +500,19 @@ playlist_iter_func (GtkTreeModel *model,
 
 	gtk_tree_model_get (model, iter, 0, &entry, -1);
 
-	*uri = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_LOCATION);
-	*title = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_TITLE);
-	*custom_title = FALSE;
+	if (uri != NULL) {
+		*uri = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_LOCATION);
+	}
+	if (title != NULL) {
+		*title = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_TITLE);
+	}
+	if (custom_title != NULL) {
+		*custom_title = FALSE;
+	}
+
+	if (entry != NULL) {
+		rhythmdb_entry_unref (entry);
+	}
 }
 #endif /* TOTEM_PL_PARSER_CHECK_VERSION */
 
@@ -643,7 +659,8 @@ rb_playlist_source_new_from_xml	(RBShell
 }
 
 void
-rb_playlist_source_save_to_xml (RBPlaylistSource *source, xmlNodePtr parent_node)
+rb_playlist_source_save_to_xml (RBPlaylistSource *source,
+				xmlNodePtr parent_node)
 {
 	xmlNodePtr node;
 	xmlChar *name;
@@ -673,6 +690,8 @@ rb_playlist_source_row_deleted (GtkTreeM
 	location = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
 	if (g_hash_table_remove (source->priv->entries, location))
 		source->priv->dirty = TRUE;
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -691,8 +710,10 @@ rb_playlist_source_entry_added_cb (Rhyth
 }
 
 static void
-rb_playlist_source_track_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-					 GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_playlist_source_track_cell_data_func (GtkTreeViewColumn *column,
+					 GtkCellRenderer *renderer,
+					 GtkTreeModel *tree_model,
+					 GtkTreeIter *iter,
 					 RBPlaylistSource *source)
 {
 	char *str;
Index: sources/rb-podcast-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-podcast-source.c,v
retrieving revision 1.73
diff -p -u -r1.73 rb-podcast-source.c
--- sources/rb-podcast-source.c	17 Jul 2006 14:52:43 -0000	1.73
+++ sources/rb-podcast-source.c	21 Jul 2006 21:31:33 -0000
@@ -1153,6 +1153,8 @@ construct_query_from_selection (RBPodcas
 				       RHYTHMDB_QUERY_SUBQUERY,
 				       subquery,
 				       RHYTHMDB_QUERY_END);
+
+		rhythmdb_query_free (subquery);
 	}
 
 	if (source->priv->selected_feeds) {
@@ -1171,7 +1173,7 @@ construct_query_from_selection (RBPodcas
 					       RHYTHMDB_PROP_SUBTITLE,
 					       location,
 					       RHYTHMDB_QUERY_END);
-			if (g_list_next(l))
+			if (g_list_next (l))
 				rhythmdb_query_append (source->priv->db, subquery,
 						       RHYTHMDB_QUERY_DISJUNCTION);
 		}
@@ -1179,6 +1181,8 @@ construct_query_from_selection (RBPodcas
 		rhythmdb_query_append (source->priv->db, query,
 				       RHYTHMDB_QUERY_SUBQUERY, subquery,
 				       RHYTHMDB_QUERY_END);
+
+		rhythmdb_query_free (subquery);
 	}
 
 	return query;
@@ -1492,19 +1496,19 @@ rb_podcast_source_post_status_cell_data_
 
 	switch (rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_STATUS)) {
 	case RHYTHMDB_PODCAST_STATUS_COMPLETE:
-		g_object_set (G_OBJECT (renderer), "text", _("Downloaded"), NULL);
+		g_object_set (renderer, "text", _("Downloaded"), NULL);
 		value = 100;
 		break;
 	case RHYTHMDB_PODCAST_STATUS_ERROR:
-		g_object_set (G_OBJECT (renderer), "text", _("Failed"), NULL);
+		g_object_set (renderer, "text", _("Failed"), NULL);
 		value = 0;
 		break;
 	case RHYTHMDB_PODCAST_STATUS_WAITING:
-		g_object_set (G_OBJECT (renderer), "text", _("Waiting"), NULL);
+		g_object_set (renderer, "text", _("Waiting"), NULL);
 		value = 0;
 		break;
 	case RHYTHMDB_PODCAST_STATUS_PAUSED:
-		g_object_set (G_OBJECT (renderer), "text", "", NULL);
+		g_object_set (renderer, "text", "", NULL);
 		value = 0;
 		break;
 	default:
@@ -1514,16 +1518,18 @@ rb_podcast_source_post_status_cell_data_
 			value = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_STATUS);
 			s = g_strdup_printf ("%u %%", value);
 
-			g_object_set (G_OBJECT (renderer), "text", s, NULL);
+			g_object_set (renderer, "text", s, NULL);
 			g_free (s);
 		}
 	}
 
-	g_object_set (G_OBJECT (renderer), "visible",
+	g_object_set (renderer, "visible",
 		      rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_STATUS) != RHYTHMDB_PODCAST_STATUS_PAUSED,
 		      NULL);
 
-	g_object_set (G_OBJECT (renderer), "value", value, NULL);
+	g_object_set (renderer, "value", value, NULL);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -1540,7 +1546,9 @@ rb_podcast_source_post_feed_cell_data_fu
 	gtk_tree_model_get (tree_model, iter, 0, &entry, -1);
 	album = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM);
 
-	g_object_set (G_OBJECT (renderer), "text", album, NULL);
+	g_object_set (renderer, "text", album, NULL);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static gboolean
@@ -1559,6 +1567,7 @@ rb_podcast_source_feed_title_search_func
 	gtk_tree_model_get (model, iter,
 			    RHYTHMDB_PROPERTY_MODEL_COLUMN_TITLE, &title,
 			    -1);
+
 	entry = rhythmdb_entry_lookup_by_location (source->priv->db, title);
 	if (entry != NULL) {
 		g_free (title);
@@ -1569,6 +1578,7 @@ rb_podcast_source_feed_title_search_func
 
 	g_free (fold_key);
 	g_free (title);
+
 	return !ret;
 }
 
@@ -1646,6 +1656,8 @@ rb_podcast_source_post_date_cell_data_fu
 
 	g_object_set (G_OBJECT (renderer), "text", str, NULL);
 	g_free (str);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
Index: sources/rb-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-source.c,v
retrieving revision 1.75
diff -p -u -r1.75 rb-source.c
--- sources/rb-source.c	17 Jul 2006 14:52:43 -0000	1.75
+++ sources/rb-source.c	21 Jul 2006 21:31:33 -0000
@@ -60,7 +60,7 @@ static gboolean default_try_playlist (RB
 static RBSourceEOFType default_handle_eos (RBSource *source);
 static gboolean default_show_popup  (RBSource *source);
 static void default_delete_thyself (RBSource *source);
-static RBEntryView* default_get_entry_view (RBSource *source);
+static RBEntryView *default_get_entry_view (RBSource *source);
 static void default_activate (RBSource *source);
 static void default_deactivate (RBSource *source);
 static void default_add_to_queue (RBSource *source, RBSource *queue);
@@ -475,7 +475,10 @@ rb_source_get_property (GObject *object,
 }
 
 static void
-default_get_status (RBSource *source, char **text, char **progress_text, float *progress)
+default_get_status (RBSource *source,
+		    char **text,
+		    char **progress_text,
+		    float *progress)
 {
 	RBSourcePrivate *priv = RB_SOURCE_GET_PRIVATE (source);
 	/* hack to get these strings marked for translation */
@@ -506,7 +509,10 @@ default_get_status (RBSource *source, ch
  * the progress bar will be hidden.
  **/
 void
-rb_source_get_status (RBSource *source, char **text, char **progress_text, float *progress)
+rb_source_get_status (RBSource *source,
+		      char **text,
+		      char **progress_text,
+		      float *progress)
 {
 	RBSourceClass *klass = RB_SOURCE_GET_CLASS (source);
 
@@ -536,7 +542,8 @@ rb_source_can_browse (RBSource *source)
 }
 
 void
-rb_source_browser_toggled (RBSource *source, gboolean enabled)
+rb_source_browser_toggled (RBSource *source,
+			   gboolean enabled)
 {
 	RBSourceClass *klass = RB_SOURCE_GET_CLASS (source);
 
@@ -557,7 +564,9 @@ rb_source_notify_filter_changed (RBSourc
 }
 
 void
-rb_source_update_play_statistics (RBSource *source, RhythmDB *db, RhythmDBEntry *entry)
+rb_source_update_play_statistics (RBSource *source,
+				  RhythmDB *db,
+				  RhythmDBEntry *entry)
 {
 	time_t now;
 	gulong current_count;
@@ -640,7 +649,8 @@ rb_source_can_search (RBSource *source)
 }
 
 void
-rb_source_search (RBSource *source, const char *text)
+rb_source_search (RBSource *source,
+		  const char *text)
 {
 	RBSourceClass *klass = RB_SOURCE_GET_CLASS (source);
 
@@ -650,7 +660,8 @@ rb_source_search (RBSource *source, cons
 }
 
 GtkWidget *
-rb_source_get_config_widget (RBSource *source, RBShellPreferences *prefs)
+rb_source_get_config_widget (RBSource *source,
+			     RBShellPreferences *prefs)
 {
 	RBSourceClass *klass = RB_SOURCE_GET_CLASS (source);
 
@@ -749,7 +760,8 @@ rb_source_can_add_to_queue (RBSource *so
 }
 
 static void
-default_add_to_queue (RBSource *source, RBSource *queue)
+default_add_to_queue (RBSource *source,
+		      RBSource *queue)
 {
 	RBEntryView *songs = rb_source_get_entry_view (source);
 	GList *selection = rb_entry_view_get_selected_entries (songs);
@@ -768,7 +780,8 @@ default_add_to_queue (RBSource *source, 
 }
 
 void
-rb_source_add_to_queue (RBSource *source, RBSource *queue)
+rb_source_add_to_queue (RBSource *source,
+			RBSource *queue)
 {
 	RBSourceClass *klass = RB_SOURCE_GET_CLASS (source);
 	klass->impl_add_to_queue (source, queue);
@@ -886,7 +899,8 @@ rb_source_have_url (RBSource *source)
 }
 
 gboolean
-rb_source_receive_drag (RBSource *source, GtkSelectionData *data)
+rb_source_receive_drag (RBSource *source,
+			GtkSelectionData *data)
 {
 	RBSourceClass *klass = RB_SOURCE_GET_CLASS (source);
 
@@ -1028,7 +1042,9 @@ rb_source_post_entry_deleted_cb (GtkTree
 }
 
 static void
-rb_source_gather_hash_keys (char *key, gpointer unused, GList **data)
+rb_source_gather_hash_keys (char *key,
+			    gpointer unused,
+			    GList **data)
 {
 	*data = g_list_prepend (*data, key);
 }
Index: sources/rb-sourcelist-model.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-sourcelist-model.c,v
retrieving revision 1.29
diff -p -u -r1.29 rb-sourcelist-model.c
--- sources/rb-sourcelist-model.c	17 Jul 2006 14:52:43 -0000	1.29
+++ sources/rb-sourcelist-model.c	21 Jul 2006 21:31:33 -0000
@@ -213,7 +213,7 @@ rb_sourcelist_model_new (void)
 	column_types[RB_SOURCELIST_MODEL_COLUMN_PLAYING] = G_TYPE_BOOLEAN;
 	column_types[RB_SOURCELIST_MODEL_COLUMN_PIXBUF] = GDK_TYPE_PIXBUF;
 	column_types[RB_SOURCELIST_MODEL_COLUMN_NAME] = G_TYPE_STRING;
-	column_types[RB_SOURCELIST_MODEL_COLUMN_SOURCE] = G_TYPE_POINTER;
+	column_types[RB_SOURCELIST_MODEL_COLUMN_SOURCE] = G_TYPE_OBJECT;
 	column_types[RB_SOURCELIST_MODEL_COLUMN_ATTRIBUTES] = PANGO_TYPE_ATTR_LIST;
 	column_types[RB_SOURCELIST_MODEL_COLUMN_VISIBILITY] = G_TYPE_BOOLEAN;
 	store = gtk_tree_store_newv (RB_SOURCELIST_MODEL_N_COLUMNS,
@@ -315,6 +315,8 @@ rb_sourcelist_model_is_row_visible (GtkT
 		gboolean visible;
 		g_object_get (source, "visibility", &visible, NULL);
 
+		g_object_unref (source);
+
 		return visible;
 	} else {
 		return real_row_is_separator (sourcelist, iter);
@@ -332,8 +334,10 @@ rb_sourcelist_model_row_is_separator (Gt
 	/* rows with actual sources are never separators */
 	gtk_tree_model_get (GTK_TREE_MODEL (model), iter,
 			    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &source, -1);
-	if (source != NULL)
+	if (source != NULL) {
+		g_object_unref (source);
 		return FALSE;
+	}
 
 	gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (sourcelist),
 							  &real_iter,
@@ -378,14 +382,20 @@ rb_sourcelist_model_drag_data_received (
 		RBSource *target;
 		rb_debug ("text/uri-list drag data received");
 
-		if (dest == NULL || !gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, dest))
+		if (dest == NULL || !gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, dest)) {
 			target = NULL;
-		else
+		} else {
 			gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
 					    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &target, -1);
+		}
 
 		g_signal_emit (G_OBJECT (model), rb_sourcelist_model_signals[DROP_RECEIVED],
 			       0, target, pos, selection_data);
+
+		if (target != NULL) {
+			g_object_unref (target);
+		}
+
 		return TRUE;
 	}
 
@@ -431,6 +441,7 @@ rb_sourcelist_model_drag_data_received (
 				    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &source,
 				    -1);
 		g_object_get (source, "sourcelist-group", &group, NULL);
+		g_object_unref (source);
 
 		/* restrict sources to within their group */
 		dest_group = get_group_for_path (model, real_dest);
@@ -496,6 +507,9 @@ path_is_droppable (RBSourceListModel *mo
 		   GtkTreePath *dest)
 {
 	GtkTreeIter iter;
+	gboolean res;
+
+	res = FALSE;
 
 	if (gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, dest)) {
 		RBSource *source;
@@ -503,10 +517,13 @@ path_is_droppable (RBSourceListModel *mo
 		gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
 				    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &source, -1);
 
-		if (source)
-			return rb_source_can_paste (source);
+		if (source != NULL) {
+			res = rb_source_can_paste (source);
+			g_object_unref (source);
+		}
 	}
-	return FALSE;
+
+	return res;
 }
 
 static gboolean
@@ -514,20 +531,25 @@ path_is_reorderable (RBSourceListModel *
 		     GtkTreePath *dest)
 {
 	GtkTreeIter iter;
+
 	if (gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, dest)) {
 		RBSource *source;
 		RBSourceListGroup group;
+
 		gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
 				    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &source, -1);
+
 		if (source == NULL)
 			return FALSE;
 
 		g_object_get (source, "sourcelist-group", &group, NULL);
+		g_object_unref (source);
 
 		/* fixed and transient sources are not reorderable, everything else is */
 		return (group != RB_SOURCELIST_GROUP_FIXED &&
 			group != RB_SOURCELIST_GROUP_TRANSIENT);
 	}
+
 	return FALSE;
 }
 
@@ -625,6 +647,7 @@ rb_sourcelist_model_row_draggable (RbTre
 				    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &source, -1);
 
 		g_object_get (source, "sourcelist-group", &group, NULL);
+		g_object_unref (source);
 
 		return (group != RB_SOURCELIST_GROUP_FIXED &&
 			group != RB_SOURCELIST_GROUP_TRANSIENT);
@@ -677,14 +700,16 @@ rb_sourcelist_model_drag_data_get (RbTre
 		gtk_tree_model_get (GTK_TREE_MODEL (drag_source), &iter,
 				    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &source, -1);
 		g_object_get (source, "query-model", &query_model, NULL);
+		g_object_unref (source);
 
 		if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (query_model), &iter)) {
-			g_object_unref (G_OBJECT (query_model));
+			g_object_unref (query_model);
 			return FALSE;
 		}
 
 		do {
 			RhythmDBEntry *entry;
+
 			if (first) {
 				g_string_append(data, "\r\n");
 				first = FALSE;
@@ -692,6 +717,8 @@ rb_sourcelist_model_drag_data_get (RbTre
 
 			entry = rhythmdb_query_model_iter_to_entry (query_model, &iter);
 			g_string_append (data, rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION));
+
+			rhythmdb_entry_unref (entry);
 
 		} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (query_model), &iter));
 
Index: sources/rb-sourcelist.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-sourcelist.c,v
retrieving revision 1.41
diff -p -u -r1.41 rb-sourcelist.c
--- sources/rb-sourcelist.c	17 Jul 2006 14:52:43 -0000	1.41
+++ sources/rb-sourcelist.c	21 Jul 2006 21:31:33 -0000
@@ -440,6 +440,7 @@ rb_sourcelist_append (RBSourceList *sour
 						    -1);
 
 			} while (check_name && (strlen (check_name)) > 0 && (g_utf8_collate (name, check_name) > 0));
+
 			g_free (check_name);
 
 		} else {
@@ -483,22 +484,32 @@ typedef struct _SourcePath {
 } SourcePath;
 
 static gboolean
-match_source_to_iter (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
+match_source_to_iter (GtkTreeModel *model,
+		      GtkTreePath *path,
+		      GtkTreeIter *iter,
 		      SourcePath *sp)
 {
 	RBSource *target = NULL;
+	gboolean  res;
 
 	gtk_tree_model_get (model, iter, RB_SOURCELIST_MODEL_COLUMN_SOURCE, &target, -1);
+
+	res = FALSE;
 	if (target == sp->source) {
 		sp->path = gtk_tree_path_copy (path);
-		return TRUE;
+		res = TRUE;
+	}
+
+	if (target != NULL) {
+		g_object_unref (target);
 	}
 
-	return FALSE;
+	return res;
 }
 
 static gboolean
-rb_sourcelist_source_to_iter (RBSourceList *sourcelist, RBSource *source,
+rb_sourcelist_source_to_iter (RBSourceList *sourcelist,
+			      RBSource *source,
 			      GtkTreeIter *iter)
 {
 	SourcePath *sp = g_new0 (SourcePath,1);
@@ -520,7 +531,8 @@ rb_sourcelist_source_to_iter (RBSourceLi
 }
 
 static gboolean
-rb_sourcelist_visible_source_to_iter (RBSourceList *sourcelist, RBSource *source,
+rb_sourcelist_visible_source_to_iter (RBSourceList *sourcelist,
+				      RBSource *source,
 				      GtkTreeIter *iter)
 {
 	SourcePath *sp = g_new0 (SourcePath,1);
@@ -542,7 +554,8 @@ rb_sourcelist_visible_source_to_iter (RB
 }
 
 void
-rb_sourcelist_edit_source_name (RBSourceList *sourcelist, RBSource *source)
+rb_sourcelist_edit_source_name (RBSourceList *sourcelist,
+				RBSource *source)
 {
 	GtkTreeIter iter;
 	GtkTreePath *path;
@@ -564,7 +577,9 @@ rb_sourcelist_edit_source_name (RBSource
 }
 
 static void
-set_source_playing (RBSourceList *sourcelist, RBSource *source, gboolean playing)
+set_source_playing (RBSourceList *sourcelist,
+		    RBSource *source,
+		    gboolean playing)
 {
 	GtkTreeIter iter;
 	g_assert (rb_sourcelist_source_to_iter (sourcelist, source, &iter));
@@ -573,7 +588,8 @@ set_source_playing (RBSourceList *source
 }
 
 void
-rb_sourcelist_set_playing_source (RBSourceList *sourcelist, RBSource *source)
+rb_sourcelist_set_playing_source (RBSourceList *sourcelist,
+				  RBSource *source)
 {
 	if (sourcelist->priv->playing_source)
 		set_source_playing (sourcelist, sourcelist->priv->playing_source, FALSE);
@@ -584,7 +600,8 @@ rb_sourcelist_set_playing_source (RBSour
 }
 
 void
-rb_sourcelist_remove (RBSourceList *sourcelist, RBSource *source)
+rb_sourcelist_remove (RBSourceList *sourcelist,
+		      RBSource *source)
 {
 	GtkTreeIter iter;
 
@@ -610,7 +627,8 @@ rb_sourcelist_remove (RBSourceList *sour
 }
 
 void
-rb_sourcelist_select (RBSourceList *sourcelist, RBSource *source)
+rb_sourcelist_select (RBSourceList *sourcelist,
+		      RBSource *source)
 {
 	GtkTreeIter iter;
 
@@ -635,14 +653,20 @@ rb_sourcelist_selection_changed_cb (GtkT
 			    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &target, -1);
 	if (target == NULL)
 		return;
+
 	g_return_if_fail (RB_IS_SOURCE (target));
 	source = target;
 	g_signal_emit (G_OBJECT (sourcelist), rb_sourcelist_signals[SELECTED], 0, source);
+
+	g_object_unref (target);
 }
 
 static void
-drop_received_cb (RBSourceListModel *model, RBSource *target, GtkTreeViewDropPosition pos,
-		  GtkSelectionData *data, RBSourceList *sourcelist)
+drop_received_cb (RBSourceListModel *model,
+		  RBSource *target,
+		  GtkTreeViewDropPosition pos,
+		  GtkSelectionData *data,
+		  RBSourceList *sourcelist)
 {
 	rb_debug ("drop recieved");
 	/* Proxy the signal. */
@@ -663,8 +687,10 @@ row_activated_cb (GtkTreeView *treeview,
 	g_return_if_fail (gtk_tree_model_get_iter (model, &iter, path));
 	gtk_tree_model_get (model, &iter, RB_SOURCELIST_MODEL_COLUMN_SOURCE, &target, -1);
 
-	if (target)
+	if (target != NULL) {
 		g_signal_emit (G_OBJECT (sourcelist), rb_sourcelist_signals[SOURCE_ACTIVATED], 0, target);
+		g_object_unref (target);
+	}
 }
 
 static gboolean
@@ -683,10 +709,15 @@ emit_show_popup (GtkTreeView *treeview,
 			    RB_SOURCELIST_MODEL_COLUMN_SOURCE, &target, -1);
 	if (target == NULL)
 		return FALSE;
+
 	g_return_val_if_fail (RB_IS_SOURCE (target), FALSE);
 
 	g_signal_emit (G_OBJECT (sourcelist), rb_sourcelist_signals[SHOW_POPUP], 0, target, &ret);
 
+	if (target != NULL) {
+		g_object_unref (target);
+	}
+
 	return ret;
 }
 
@@ -724,6 +755,7 @@ key_release_cb (GtkTreeView *treeview,
 {
 	GtkTreeIter iter;
 	RBSource *target;
+	gboolean res;
 
 	/* F2 = rename playlist */
 	if (event->keyval != GDK_F2)
@@ -737,13 +769,15 @@ key_release_cb (GtkTreeView *treeview,
 	if (target == NULL)
 		return FALSE;
 
-	g_return_val_if_fail (RB_IS_SOURCE (target), FALSE);
+	res = FALSE;
 	if (rb_source_can_rename (target)) {
 		rb_sourcelist_edit_source_name (sourcelist, target);
-		return TRUE;
+		res = TRUE;
 	}
 
-	return FALSE;
+	g_object_unref (target);
+
+	return res;
 }
 
 static gboolean
@@ -754,7 +788,9 @@ popup_menu_cb (GtkTreeView *treeview,
 }
 
 static void
-name_notify_cb (GObject *obj, GParamSpec *pspec, gpointer data)
+name_notify_cb (GObject *obj,
+		GParamSpec *pspec,
+		gpointer data)
 {
 	RBSourceList *sourcelist = RB_SOURCELIST (data);
 	RBSource *source = RB_SOURCE (obj);
@@ -773,7 +809,9 @@ name_notify_cb (GObject *obj, GParamSpec
 }
 
 static void
-visibility_notify_cb (GObject *obj, GParamSpec *pspec, gpointer data)
+visibility_notify_cb (GObject *obj,
+		      GParamSpec *pspec,
+		      gpointer data)
 {
 	RBSourceList *sourcelist = RB_SOURCELIST (data);
 	RBSource *source = RB_SOURCE (obj);
@@ -812,8 +850,10 @@ visibility_notify_cb (GObject *obj, GPar
 }
 
 static void
-rb_sourcelist_title_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-				    GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_sourcelist_title_cell_data_func (GtkTreeViewColumn *column,
+				    GtkCellRenderer *renderer,
+				    GtkTreeModel *tree_model,
+				    GtkTreeIter *iter,
 				    RBSourceList *sourcelist)
 {
 	char *str;
@@ -832,8 +872,10 @@ rb_sourcelist_title_cell_data_func (GtkT
 }
 
 static void
-source_name_edited_cb (GtkCellRendererText *renderer, const char *pathstr,
-		       const char *text, RBSourceList *sourcelist)
+source_name_edited_cb (GtkCellRendererText *renderer,
+		       const char *pathstr,
+		       const char *text,
+		       RBSourceList *sourcelist)
 {
 	GtkTreePath *path;
 	GtkTreeIter iter;
@@ -858,6 +900,8 @@ source_name_edited_cb (GtkCellRendererTe
 	g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL);
 
 	gtk_tree_view_columns_autosize (GTK_TREE_VIEW (sourcelist->priv->treeview));
+
+	g_object_unref (source);
 }
 
 static void
Index: sources/rb-static-playlist-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-static-playlist-source.c,v
retrieving revision 1.27
diff -p -u -r1.27 rb-static-playlist-source.c
--- sources/rb-static-playlist-source.c	17 Jul 2006 14:52:43 -0000	1.27
+++ sources/rb-static-playlist-source.c	21 Jul 2006 21:31:34 -0000
@@ -518,7 +518,9 @@ impl_save_contents_to_xml (RBPlaylistSou
 		encoded = xmlEncodeEntitiesReentrant (NULL, BAD_CAST location);
 
 		xmlNodeSetContent (child_node, encoded);
+
 		g_free (encoded);
+		rhythmdb_entry_unref (entry);
 	} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->base_model), &iter));
 }
 
@@ -586,6 +588,7 @@ rb_static_playlist_source_add_location_i
 		rhythmdb_entry_ref (entry);
 		rhythmdb_query_model_add_entry (priv->base_model, entry, index);
 		rhythmdb_entry_unref (entry);
+
 		g_boxed_free (RHYTHMDB_TYPE_ENTRY_TYPE, entry_type);
 	}
 
@@ -713,6 +716,8 @@ rb_static_playlist_source_row_inserted (
 	gtk_tree_model_get (model, iter, 0, &entry, -1);
 
 	rb_static_playlist_source_add_entry (source, entry, -1);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static GList *
Index: widgets/rb-entry-view.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/rb-entry-view.c,v
retrieving revision 1.153
diff -p -u -r1.153 rb-entry-view.c
--- widgets/rb-entry-view.c	20 Jul 2006 03:06:12 -0000	1.153
+++ widgets/rb-entry-view.c	21 Jul 2006 21:31:37 -0000
@@ -190,8 +190,10 @@ static guint rb_entry_view_signals[LAST_
 static GQuark rb_entry_view_column_always_visible;
 
 static gboolean
-type_ahead_search_func (GtkTreeModel *model, gint column,
-			const gchar *key, GtkTreeIter *iter,
+type_ahead_search_func (GtkTreeModel *model,
+			gint column,
+			const gchar *key,
+			GtkTreeIter *iter,
 			gpointer search_data)
 {
 	RhythmDBEntry *entry;
@@ -202,11 +204,14 @@ type_ahead_search_func (GtkTreeModel *mo
 	gtk_tree_model_get (model, iter, 0, &entry, -1);
 	folded = rb_search_fold (key);
 	entry_folded = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE_FOLDED);
+	rhythmdb_entry_unref (entry);
+
 	if (entry_folded == NULL || folded == NULL)
 		return 1;
 
 	res = (strstr (entry_folded, folded) == NULL);
 	g_free (folded);
+
 	return res;
 }
 
@@ -412,12 +417,15 @@ rb_entry_view_finalize (GObject *object)
 	g_hash_table_destroy (view->priv->column_sort_data_map);
 	g_hash_table_destroy (view->priv->column_key_map);
 
-	if (view->priv->playing_pixbuf)
-		g_object_unref (G_OBJECT (view->priv->playing_pixbuf));
-	if (view->priv->paused_pixbuf)
-		g_object_unref (G_OBJECT (view->priv->paused_pixbuf));
-	if (view->priv->error_pixbuf)
-		g_object_unref (G_OBJECT (view->priv->error_pixbuf));
+	if (view->priv->playing_pixbuf != NULL)
+		g_object_unref (view->priv->playing_pixbuf);
+	if (view->priv->paused_pixbuf != NULL)
+		g_object_unref (view->priv->paused_pixbuf);
+	if (view->priv->error_pixbuf != NULL)
+		g_object_unref (view->priv->error_pixbuf);
+	if (view->priv->playing_entry != NULL) {
+		g_object_unref (view->priv->playing_model);
+	}
 
 	g_free (view->priv->sorting_key);
 	g_free (view->priv->sorting_column_name);
@@ -594,7 +602,8 @@ rb_entry_view_new (RhythmDB *db,
 }
 
 void
-rb_entry_view_set_model (RBEntryView *view, RhythmDBQueryModel *model)
+rb_entry_view_set_model (RBEntryView *view,
+			 RhythmDBQueryModel *model)
 {
 	g_object_set (G_OBJECT (view), "model", model, NULL);
 }
@@ -606,8 +615,10 @@ struct RBEntryViewCellDataFuncData {
 };
 
 static void
-rb_entry_view_playing_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-				      GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_entry_view_playing_cell_data_func (GtkTreeViewColumn *column,
+				      GtkCellRenderer *renderer,
+				      GtkTreeModel *tree_model,
+				      GtkTreeIter *iter,
 				      RBEntryView *view)
 {
 	RhythmDBEntry *entry;
@@ -615,6 +626,10 @@ rb_entry_view_playing_cell_data_func (Gt
 
 	entry = rhythmdb_query_model_iter_to_entry (view->priv->model, iter);
 
+	if (entry == NULL) {
+		return;
+	}
+
 	if (entry == view->priv->playing_entry) {
 		switch (view->priv->playing_state) {
 		case RB_ENTRY_VIEW_PLAYING:
@@ -633,26 +648,34 @@ rb_entry_view_playing_cell_data_func (Gt
 		pixbuf = view->priv->error_pixbuf;
 	}
 
-	g_object_set (G_OBJECT (renderer), "pixbuf", pixbuf, NULL);
+	g_object_set (renderer, "pixbuf", pixbuf, NULL);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
-rb_entry_view_rating_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-				     GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_entry_view_rating_cell_data_func (GtkTreeViewColumn *column,
+				     GtkCellRenderer *renderer,
+				     GtkTreeModel *tree_model,
+				     GtkTreeIter *iter,
 				     RBEntryView *view)
 {
 	RhythmDBEntry *entry;
 
 	entry = rhythmdb_query_model_iter_to_entry (view->priv->model, iter);
 
-	g_object_set (G_OBJECT (renderer),
+	g_object_set (renderer,
 		      "rating", rhythmdb_entry_get_double (entry, RHYTHMDB_PROP_RATING),
 		      NULL);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
-rb_entry_view_long_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-				   GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_entry_view_long_cell_data_func (GtkTreeViewColumn *column,
+				   GtkCellRenderer *renderer,
+				   GtkTreeModel *tree_model,
+				   GtkTreeIter *iter,
 				   struct RBEntryViewCellDataFuncData *data)
 {
 	RhythmDBEntry *entry;
@@ -668,13 +691,16 @@ rb_entry_view_long_cell_data_func (GtkTr
 	else
 		str = g_strdup ("");
 
-	g_object_set (G_OBJECT (renderer), "text", str, NULL);
+	g_object_set (renderer, "text", str, NULL);
 	g_free (str);
+	rhythmdb_entry_unref (entry);
 }
 
 static void
-rb_entry_view_play_count_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-					 GtkTreeModel *tree_model, GtkTreeIter * iter,
+rb_entry_view_play_count_cell_data_func (GtkTreeViewColumn *column,
+					 GtkCellRenderer *renderer,
+					 GtkTreeModel *tree_model,
+					 GtkTreeIter * iter,
 					 struct RBEntryViewCellDataFuncData *data)
 {
 	RhythmDBEntry *entry;
@@ -689,14 +715,18 @@ rb_entry_view_play_count_cell_data_func 
 	else
 		str = g_strdup_printf ("%ld", i);
 
-	g_object_set (G_OBJECT (renderer), "text", str, NULL);
+	g_object_set (renderer, "text", str, NULL);
 	if (i != 0)
 		g_free (str);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
-rb_entry_view_duration_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-				       GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_entry_view_duration_cell_data_func (GtkTreeViewColumn *column,
+				       GtkCellRenderer *renderer,
+				       GtkTreeModel *tree_model,
+				       GtkTreeIter *iter,
 				       struct RBEntryViewCellDataFuncData *data)
 {
 	RhythmDBEntry *entry;
@@ -707,13 +737,16 @@ rb_entry_view_duration_cell_data_func (G
 	duration = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION);
 
 	str = rb_make_duration_string (duration);
-	g_object_set (G_OBJECT (renderer), "text", str, NULL);
+	g_object_set (renderer, "text", str, NULL);
 	g_free (str);
+	rhythmdb_entry_unref (entry);
 }
 
 static void
-rb_entry_view_year_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-				   GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_entry_view_year_cell_data_func (GtkTreeViewColumn *column,
+				   GtkCellRenderer *renderer,
+				   GtkTreeModel *tree_model,
+				   GtkTreeIter *iter,
 				   struct RBEntryViewCellDataFuncData *data)
 {
 	RhythmDBEntry *entry;
@@ -727,16 +760,20 @@ rb_entry_view_year_cell_data_func (GtkTr
 	if (julian > 0) {
 		date = g_date_new_julian (julian);
 		g_date_strftime (str, sizeof (str), "%Y", date);
-		g_object_set (G_OBJECT (renderer), "text", str, NULL);
+		g_object_set (renderer, "text", str, NULL);
 		g_date_free (date);
 	} else {
-		g_object_set (G_OBJECT (renderer), "text", _("Unknown"), NULL);
+		g_object_set (renderer, "text", _("Unknown"), NULL);
 	}
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
-rb_entry_view_quality_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-				      GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_entry_view_quality_cell_data_func (GtkTreeViewColumn *column,
+				      GtkCellRenderer *renderer,
+				      GtkTreeModel *tree_model,
+				      GtkTreeIter *iter,
 				      struct RBEntryViewCellDataFuncData *data)
 {
 	RhythmDBEntry *entry;
@@ -748,16 +785,20 @@ rb_entry_view_quality_cell_data_func (Gt
 
 	if (bitrate > 0) {
 		char *s = g_strdup_printf (_("%u kbps"), (guint)bitrate);
-		g_object_set (G_OBJECT (renderer), "text", s, NULL);
+		g_object_set (renderer, "text", s, NULL);
 		g_free (s);
 	} else {
-		g_object_set (G_OBJECT (renderer), "text", _("Unknown"), NULL);
+		g_object_set (renderer, "text", _("Unknown"), NULL);
 	}
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
-rb_entry_view_location_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-				       GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_entry_view_location_cell_data_func (GtkTreeViewColumn *column,
+				       GtkCellRenderer *renderer,
+				       GtkTreeModel *tree_model,
+				       GtkTreeIter *iter,
 				       struct RBEntryViewCellDataFuncData *data)
 {
 	RhythmDBEntry *entry;
@@ -769,13 +810,17 @@ rb_entry_view_location_cell_data_func (G
 	location = rhythmdb_entry_get_string (entry, data->propid);
 	str = gnome_vfs_unescape_string_for_display (location);
 
-	g_object_set (G_OBJECT (renderer), "text", str, NULL);
+	g_object_set (renderer, "text", str, NULL);
 	g_free (str);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
-rb_entry_view_string_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
-				     GtkTreeModel *tree_model, GtkTreeIter *iter,
+rb_entry_view_string_cell_data_func (GtkTreeViewColumn *column,
+				     GtkCellRenderer *renderer,
+				     GtkTreeModel *tree_model,
+				     GtkTreeIter *iter,
 				     struct RBEntryViewCellDataFuncData *data)
 {
 	RhythmDBEntry *entry;
@@ -784,9 +829,11 @@ rb_entry_view_string_cell_data_func (Gtk
 	entry = rhythmdb_query_model_iter_to_entry (data->view->priv->model, iter);
 
 	str = rhythmdb_entry_get_string (entry, data->propid);
+	if (str != NULL) {
+		g_object_set (renderer, "text", str, NULL);
+	}
 
-	g_object_set (G_OBJECT (renderer), "text", str, NULL);
-
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -794,18 +841,21 @@ rb_entry_view_sync_sorting (RBEntryView 
 {
 	GtkTreeViewColumn *column;
 	gint direction;
-	const char *column_name;
+	char *column_name;
 
+	column_name = NULL;
 	rb_entry_view_get_sorting_order (view, &column_name, &direction);
 
-	if (!column_name)
+	if (column_name == NULL) {
 		return;
+	}
 
 	column = g_hash_table_lookup (view->priv->column_key_map, column_name);
-	if (!column)
+	if (column == NULL) {
 		return;
+	}
 
-	rb_debug("Updating EntryView sort order to %s:%d", column_name, direction);
+	rb_debug ("Updating EntryView sort order to %s:%d", column_name, direction);
 
 	/* remove the old sorting indicator */
 	if (view->priv->sorting_column)
@@ -818,6 +868,8 @@ rb_entry_view_sync_sorting (RBEntryView 
 
 	rb_debug ("emitting sort order changed");
 	g_signal_emit (G_OBJECT (view), rb_entry_view_signals[SORT_ORDER_CHANGED], 0);
+
+	g_free (column_name);
 }
 
 const char *
@@ -847,7 +899,8 @@ rb_entry_view_get_sorting_type (RBEntryV
 }
 
 void
-rb_entry_view_set_sorting_type (RBEntryView *view, const char *sorttype)
+rb_entry_view_set_sorting_type (RBEntryView *view,
+				const char *sorttype)
 {
 	char **strs;
 
@@ -858,7 +911,7 @@ rb_entry_view_set_sorting_type (RBEntryV
 
 	strs = g_strsplit (sorttype, ",", 0);
 
-	g_free(view->priv->sorting_column_name);
+	g_free (view->priv->sorting_column_name);
 	view->priv->sorting_column_name = g_strdup(strs[0]);
 
 	if (!strcmp ("ascending", strs[1]))
@@ -876,14 +929,25 @@ rb_entry_view_set_sorting_type (RBEntryV
 }
 
 void
-rb_entry_view_get_sorting_order (RBEntryView *view, const char **column_name, gint *sort_order)
+rb_entry_view_get_sorting_order (RBEntryView *view,
+				 char **column_name,
+				 gint *sort_order)
 {
-	*column_name = g_strdup (view->priv->sorting_column_name);
-	*sort_order = view->priv->sorting_order;
+ 	g_return_if_fail (RB_IS_ENTRY_VIEW (view));
+
+	if (column_name != NULL) {
+		*column_name = g_strdup (view->priv->sorting_column_name);
+	}
+
+	if (sort_order != NULL) {
+		*sort_order = view->priv->sorting_order;
+	}
 }
 
 void
-rb_entry_view_set_sorting_order (RBEntryView *view, const char *column_name, gint sort_order)
+rb_entry_view_set_sorting_order (RBEntryView *view,
+				 const char *column_name,
+				 gint sort_order)
 {
 	if (column_name == NULL)
 		return;
@@ -922,7 +986,9 @@ rb_entry_view_column_clicked_cb (GtkTree
 }
 
 void
-rb_entry_view_append_column (RBEntryView *view, RBEntryViewColumn coltype, gboolean always_visible)
+rb_entry_view_append_column (RBEntryView *view,
+			     RBEntryViewColumn coltype,
+			     gboolean always_visible)
 {
 	GtkTreeViewColumn *column;
 	GtkCellRenderer *renderer = NULL;
@@ -943,8 +1009,7 @@ rb_entry_view_append_column (RBEntryView
 	cell_data = g_new0 (struct RBEntryViewCellDataFuncData, 1);
 	cell_data->view = view;
 
-	switch (coltype)
-	{
+	switch (coltype) {
 	case RB_ENTRY_VIEW_COL_TRACK_NUMBER:
 		propid = RHYTHMDB_PROP_TRACK_NUMBER;
 		cell_data->propid = propid;
@@ -1215,7 +1280,8 @@ rb_entry_view_insert_column_custom (RBEn
 }
 
 void
-rb_entry_view_set_columns_clickable (RBEntryView *view, gboolean clickable)
+rb_entry_view_set_columns_clickable (RBEntryView *view,
+				     gboolean clickable)
 {
 	GList *columns, *tem;
 
@@ -1230,7 +1296,8 @@ rb_entry_view_set_columns_clickable (RBE
 }
 
 static GObject *
-rb_entry_view_constructor (GType type, guint n_construct_properties,
+rb_entry_view_constructor (GType type,
+			   guint n_construct_properties,
 			   GObjectConstructParam *construct_properties)
 {
 	RBEntryView *view;
@@ -1342,7 +1409,7 @@ rb_entry_view_constructor (GType type, g
 		RhythmDBQueryModel *query_model;
 		query_model = rhythmdb_query_model_new_empty (view->priv->db);
 		rb_entry_view_set_model (view, RHYTHMDB_QUERY_MODEL (query_model));
-		g_object_unref (G_OBJECT (query_model));
+		g_object_unref (query_model);
 	}
 
 	return G_OBJECT (view);
@@ -1350,9 +1417,9 @@ rb_entry_view_constructor (GType type, g
 
 static void
 rb_entry_view_rated_cb (RBCellRendererRating *cellrating,
-		       const char *path_string,
-		       double rating,
-		       RBEntryView *view)
+			const char *path_string,
+			double rating,
+			RBEntryView *view)
 {
 	GtkTreePath *path;
 	RhythmDBEntry *entry;
@@ -1371,6 +1438,8 @@ rb_entry_view_rated_cb (RBCellRendererRa
 	g_value_unset (&value);
 
 	rhythmdb_commit (view->priv->db);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -1393,6 +1462,8 @@ rb_entry_view_pixbuf_clicked_cb (RBEntry
 	if (error) {
 		rb_error_dialog (NULL, _("Playback Error"), "%s", error);
 	}
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -1408,12 +1479,12 @@ rb_entry_view_playing_song_changed (RBSh
 	if (view->priv->playing_entry != NULL) {
 		if (view->priv->playing_state != RB_ENTRY_VIEW_NOT_PLAYING)
 			rb_entry_view_emit_row_changed (view, view->priv->playing_entry);
-		g_object_unref (G_OBJECT (view->priv->playing_model));
+		g_object_unref (view->priv->playing_model);
 	}
 
  	view->priv->playing_entry = entry;
- 	g_object_ref (G_OBJECT (view->priv->model));
  	view->priv->playing_model = view->priv->model;
+ 	g_object_ref (view->priv->playing_model);
 
  	if (view->priv->playing_state != RB_ENTRY_VIEW_NOT_PLAYING) {
 		if (view->priv->playing_entry != NULL) {
@@ -1435,9 +1506,8 @@ static gboolean
 harvest_entries (GtkTreeModel *model,
 		 GtkTreePath *path,
 		 GtkTreeIter *iter,
-		 void **data)
+		 GList      **list)
 {
-	GList **list = (GList **) data;
 	RhythmDBEntry *entry;
 
 	gtk_tree_model_get (model, iter, 0, &entry, -1);
@@ -1462,8 +1532,8 @@ rb_entry_view_get_selected_entries (RBEn
 
 static gboolean
 rb_entry_view_button_press_cb (GtkTreeView *treeview,
-			      GdkEventButton *event,
-			      RBEntryView *view)
+			       GdkEventButton *event,
+			       RBEntryView *view)
 {
 	if (event->button == 3) {
 		GtkTreePath *path;
@@ -1479,9 +1549,9 @@ rb_entry_view_button_press_cb (GtkTreeVi
 			if (!g_list_find (selected, entry))
 				rb_entry_view_select_entry (view, entry);
 
-			/* FIXME: unref entries */
 			g_list_free (selected);
 
+			rhythmdb_entry_unref (entry);
 		}
 		g_signal_emit (G_OBJECT (view), rb_entry_view_signals[SHOW_POPUP], 0, (path != NULL));
 		return TRUE;
@@ -1560,6 +1630,8 @@ rb_entry_view_row_activated_cb (GtkTreeV
 
 	rb_debug ("emitting entry activated");
 	g_signal_emit (G_OBJECT (view), rb_entry_view_signals[ENTRY_ACTIVATED], 0, entry);
+
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -1572,6 +1644,7 @@ rb_entry_view_row_inserted_cb (GtkTreeMo
 
 	rb_debug ("row added");
 	g_signal_emit (G_OBJECT (view), rb_entry_view_signals[ENTRY_ADDED], 0, entry);
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -1583,6 +1656,7 @@ rb_entry_view_row_deleted_cb (GtkTreeMod
 
 	rb_debug ("row deleted");
 	g_signal_emit (G_OBJECT (view), rb_entry_view_signals[ENTRY_DELETED], 0, entry);
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -1818,7 +1892,9 @@ propid_from_name (const char *name)
 }
 
 static void
-set_column_visibility (guint propid, GtkTreeViewColumn *column, GList *visible_props)
+set_column_visibility (guint propid,
+		       GtkTreeViewColumn *column,
+		       GList *visible_props)
 {
 	gboolean visible;
 
Index: widgets/rb-entry-view.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/rb-entry-view.h,v
retrieving revision 1.38
diff -p -u -r1.38 rb-entry-view.h
--- widgets/rb-entry-view.h	14 Jul 2006 12:32:01 -0000	1.38
+++ widgets/rb-entry-view.h	21 Jul 2006 21:31:37 -0000
@@ -98,25 +98,33 @@ typedef struct
 
 GType		rb_entry_view_get_type			(void);
 
-RBEntryView *	rb_entry_view_new			(RhythmDB *db, GObject *shell_player,
-							 const char *sort_key, gboolean drag_source,
+RBEntryView *	rb_entry_view_new			(RhythmDB *db,
+                                                         GObject *shell_player,
+							 const char *sort_key,
+                                                         gboolean drag_source,
 							 gboolean drag_dest);
 
 void		rb_entry_view_append_column		(RBEntryView *view,
-							 RBEntryViewColumn coltype, gboolean always_visible);
+							 RBEntryViewColumn coltype,
+                                                         gboolean always_visible);
 
-void		rb_entry_view_append_column_custom	(RBEntryView *view, GtkTreeViewColumn *column,
-							 const char *title, const char *key,
+void		rb_entry_view_append_column_custom	(RBEntryView *view,
+                                                         GtkTreeViewColumn *column,
+							 const char *title,
+                                                         const char *key,
 							 GCompareDataFunc sort_func,
 							 gpointer data);
 
-void		rb_entry_view_insert_column_custom	(RBEntryView *view, GtkTreeViewColumn *column,
-							 const char *title, const char *key,
+void		rb_entry_view_insert_column_custom	(RBEntryView *view,
+                                                         GtkTreeViewColumn *column,
+							 const char *title,
+                                                         const char *key,
 							 GCompareDataFunc sort_func,
 							 gpointer data,
 							 gint position);
 
-void		rb_entry_view_set_columns_clickable	(RBEntryView *view, gboolean clickable);
+void		rb_entry_view_set_columns_clickable	(RBEntryView *view,
+                                                         gboolean clickable);
 
 void		rb_entry_view_set_model			(RBEntryView *view,
 							 RhythmDBQueryModel *model);
@@ -146,11 +154,16 @@ void		rb_entry_view_enable_drag_source	(
 							 const GtkTargetEntry *targets,
 							 int n_targets);
 
-void		rb_entry_view_get_sorting_order		(RBEntryView *view, const char **column_name, gint *sort_order);
-void		rb_entry_view_set_sorting_order		(RBEntryView *view, const char *column_name, gint sort_order);
+void		rb_entry_view_get_sorting_order		(RBEntryView *view,
+                                                         char       **column_name,
+                                                         gint        *sort_order);
+void		rb_entry_view_set_sorting_order		(RBEntryView *view,
+                                                         const char  *column_name,
+                                                         gint         sort_order);
 /* deal with the sorting order as a composite string */
 const char *	rb_entry_view_get_sorting_type		(RBEntryView *view);
- void		rb_entry_view_set_sorting_type		(RBEntryView *view, const char *sorttype);
+ void		rb_entry_view_set_sorting_type		(RBEntryView *view,
+                                                         const char  *sorttype);
 
 void		rb_entry_view_set_fixed_column_width	(RBEntryView *view,
 							 GtkTreeViewColumn *column,
Index: widgets/rb-header.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/rb-header.c,v
retrieving revision 1.33
diff -p -u -r1.33 rb-header.c
--- widgets/rb-header.c	14 Jul 2006 12:32:01 -0000	1.33
+++ widgets/rb-header.c	21 Jul 2006 21:31:37 -0000
@@ -302,7 +302,8 @@ rb_header_new (RBShellPlayer *shell_play
 {
 	RBHeader *header;
 
-	header = RB_HEADER (g_object_new (RB_TYPE_HEADER, "shell-player", shell_player,
+	header = RB_HEADER (g_object_new (RB_TYPE_HEADER,
+					  "shell-player", shell_player,
 					  "title", NULL,
 					  "spacing", 6, NULL));
 
@@ -314,13 +315,13 @@ rb_header_new (RBShellPlayer *shell_play
 void
 rb_header_set_playing_entry (RBHeader *header, RhythmDBEntry *entry)
 {
-	g_object_set (G_OBJECT (header), "entry", entry, NULL);
+	g_object_set (header, "entry", entry, NULL);
 }
 
 void
 rb_header_set_title (RBHeader *header, const char *title)
 {
-	g_object_set (G_OBJECT (header), "title", title, NULL);
+	g_object_set (header, "title", title, NULL);
 }
 
 void
Index: widgets/rb-library-browser.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/rb-library-browser.c,v
retrieving revision 1.15
diff -p -u -r1.15 rb-library-browser.c
--- widgets/rb-library-browser.c	17 Jul 2006 14:52:55 -0000	1.15
+++ widgets/rb-library-browser.c	21 Jul 2006 21:31:37 -0000
@@ -563,10 +563,10 @@ rebuild_child_model (RBLibraryBrowser *w
 		ignore_selection_changes (widget, view, TRUE);
 
 		prop_model = rb_property_view_get_model (view);
-		g_object_set (G_OBJECT (prop_model), "query-model", child_model, NULL);
-		g_object_unref (G_OBJECT (prop_model));
+		g_object_set (prop_model, "query-model", child_model, NULL);
+		g_object_unref (prop_model);
 
-		g_object_unref (G_OBJECT (base_model));
+		g_object_unref (base_model);
 
 		rebuild_child_model (widget, property_index + 1, query_pending);
 		restore_selection (widget, property_index + 1, query_pending);
@@ -640,8 +640,8 @@ rb_library_browser_set_model (RBLibraryB
 	ignore_selection_changes (widget, view, TRUE);
 
 	prop_model = rb_property_view_get_model (view);
-	g_object_set (G_OBJECT (prop_model), "query-model", priv->input_model, NULL);
-	g_object_unref (G_OBJECT (prop_model));
+	g_object_set (prop_model, "query-model", priv->input_model, NULL);
+	g_object_unref (prop_model);
 
 	rebuild_child_model (widget, 0, query_pending);
 	restore_selection (widget, 0, query_pending);
Index: widgets/rb-property-view.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/rb-property-view.c,v
retrieving revision 1.47
diff -p -u -r1.47 rb-property-view.c
--- widgets/rb-property-view.c	14 Jul 2006 12:32:01 -0000	1.47
+++ widgets/rb-property-view.c	21 Jul 2006 21:31:37 -0000
@@ -244,6 +244,55 @@ rb_property_view_init (RBPropertyView *v
 }
 
 static void
+rb_property_view_set_model_internal (RBPropertyView *view,
+				     RhythmDBPropertyModel *model)
+{
+	if (view->priv->prop_model) {
+		g_signal_handlers_disconnect_by_func (G_OBJECT (view->priv->prop_model),
+						      G_CALLBACK (rb_property_view_pre_row_deleted_cb),
+						      view);
+		g_signal_handlers_disconnect_by_func (G_OBJECT (view->priv->prop_model),
+						      G_CALLBACK (rb_property_view_post_row_deleted_cb),
+						      view);
+		g_object_unref (view->priv->prop_model);
+	}
+
+	view->priv->prop_model = model;
+
+	if (view->priv->prop_model != NULL) {
+		GtkTreeIter iter;
+
+		g_object_ref (view->priv->prop_model);
+
+		gtk_tree_view_set_model (GTK_TREE_VIEW (view->priv->treeview),
+					 GTK_TREE_MODEL (view->priv->prop_model));
+
+		g_signal_connect_object (view->priv->prop_model,
+					 "pre-row-deletion",
+					 G_CALLBACK (rb_property_view_pre_row_deleted_cb),
+					 view,
+					 0);
+		g_signal_connect_object (view->priv->prop_model,
+					 "row_deleted",
+					 G_CALLBACK (rb_property_view_post_row_deleted_cb),
+					 view,
+					 G_CONNECT_AFTER);
+
+		g_signal_handlers_block_by_func (view->priv->selection,
+						 G_CALLBACK (rb_property_view_selection_changed_cb),
+						 view);
+
+		gtk_tree_selection_unselect_all (view->priv->selection);
+
+		if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (view->priv->prop_model), &iter))
+			gtk_tree_selection_select_iter (view->priv->selection, &iter);
+		g_signal_handlers_unblock_by_func (view->priv->selection,
+						   G_CALLBACK (rb_property_view_selection_changed_cb),
+						   view);
+	}
+}
+
+static void
 rb_property_view_finalize (GObject *object)
 {
 	RBPropertyView *view;
@@ -255,6 +304,8 @@ rb_property_view_finalize (GObject *obje
 
 	g_return_if_fail (view->priv != NULL);
 
+	rb_property_view_set_model_internal (view, NULL);
+
 	g_free (view->priv->title);
 
 	G_OBJECT_CLASS (rb_property_view_parent_class)->finalize (object);
@@ -268,8 +319,7 @@ rb_property_view_set_property (GObject *
 {
 	RBPropertyView *view = RB_PROPERTY_VIEW (object);
 
-	switch (prop_id)
-	{
+	switch (prop_id) {
 	case PROP_DB:
 		view->priv->db = g_value_get_object (value);
 		break;
@@ -280,51 +330,7 @@ rb_property_view_set_property (GObject *
 		view->priv->title = g_value_dup_string (value);
 		break;
 	case PROP_MODEL:
-	{
-		GtkTreeIter iter;
-
-		if (view->priv->prop_model) {
-			g_signal_handlers_disconnect_by_func (G_OBJECT (view->priv->prop_model),
-							      G_CALLBACK (rb_property_view_pre_row_deleted_cb),
-							      view);
-			g_signal_handlers_disconnect_by_func (G_OBJECT (view->priv->prop_model),
-							      G_CALLBACK (rb_property_view_post_row_deleted_cb),
-							      view);
-			g_object_unref (G_OBJECT (view->priv->prop_model));
-		}
-
-		view->priv->prop_model = g_value_get_object (value);
-
-		if (!view->priv->prop_model)
-			break;
-
-		gtk_tree_view_set_model (GTK_TREE_VIEW (view->priv->treeview),
-					 GTK_TREE_MODEL (view->priv->prop_model));
-
-		g_object_ref (G_OBJECT (view->priv->prop_model));
-		g_signal_connect_object (G_OBJECT (view->priv->prop_model),
-					 "pre-row-deletion",
-					 G_CALLBACK (rb_property_view_pre_row_deleted_cb),
-					 view,
-					 0);
-		g_signal_connect_object (G_OBJECT (view->priv->prop_model),
-					 "row_deleted",
-					 G_CALLBACK (rb_property_view_post_row_deleted_cb),
-					 view,
-					 G_CONNECT_AFTER);
-
-		g_signal_handlers_block_by_func (G_OBJECT (view->priv->selection),
-						 G_CALLBACK (rb_property_view_selection_changed_cb),
-						 view);
-
-		gtk_tree_selection_unselect_all (view->priv->selection);
-		if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (view->priv->prop_model), &iter))
-			gtk_tree_selection_select_iter (view->priv->selection, &iter);
-		g_signal_handlers_unblock_by_func (G_OBJECT (view->priv->selection),
-						   G_CALLBACK (rb_property_view_selection_changed_cb),
-						   view);
-
-	}
+		rb_property_view_set_model_internal (view, g_value_get_object (value));
 		break;
 	case PROP_DRAGGABLE:
 		view->priv->draggable = g_value_get_boolean (value);
@@ -343,8 +349,7 @@ rb_property_view_get_property (GObject *
 {
 	RBPropertyView *view = RB_PROPERTY_VIEW (object);
 
-	switch (prop_id)
-	{
+	switch (prop_id) {
 	case PROP_DB:
 		g_value_set_object (value, view->priv->db);
 		break;
@@ -406,8 +411,8 @@ rb_property_view_reset (RBPropertyView *
 
 	model = rhythmdb_property_model_new (view->priv->db, view->priv->propid);
 
-	g_object_set (G_OBJECT (view), "property-model", model, NULL);
-	g_object_unref (G_OBJECT (model));
+	g_object_set (view, "property-model", model, NULL);
+	g_object_unref (model);
 }
 
 RhythmDBPropertyModel *
@@ -415,14 +420,15 @@ rb_property_view_get_model (RBPropertyVi
 {
 	RhythmDBPropertyModel *model;
 
-	g_object_get (G_OBJECT (view), "property-model", &model, NULL);
+	g_object_get (view, "property-model", &model, NULL);
+
 	return model;
 }
 
 void
 rb_property_view_set_model (RBPropertyView *view, RhythmDBPropertyModel *model)
 {
-	g_object_set (G_OBJECT (view), "property-model", model, NULL);
+	g_object_set (view, "property-model", model, NULL);
 }
 
 static void
@@ -588,7 +594,7 @@ rb_property_view_row_activated_cb (GtkTr
 				   RBPropertyView *view)
 {
 	GtkTreeIter iter;
-	const char *val;
+	char *val;
 	gboolean is_all;
 
 	rb_debug ("row activated");
@@ -602,6 +608,8 @@ rb_property_view_row_activated_cb (GtkTr
 	rb_debug ("emitting property activated");
 	g_signal_emit (G_OBJECT (view), rb_property_view_signals[PROPERTY_ACTIVATED], 0,
 		       is_all ? NULL : val);
+
+	g_free (val);
 }
 
 void
@@ -728,14 +736,16 @@ rb_property_view_button_press_cb (GtkTre
 		} else {
 			GtkTreeModel *model;
 			GtkTreeIter iter;
-			const char *val;
+			char *val;
 			GList *lst = NULL;
 
 			model = gtk_tree_view_get_model (GTK_TREE_VIEW (view->priv->treeview));
 			if (gtk_tree_model_get_iter (model, &iter, path)) {
-				gtk_tree_model_get (model, &iter, 0, &val, -1);
+				gtk_tree_model_get (model, &iter,
+						    RHYTHMDB_PROPERTY_MODEL_COLUMN_TITLE, &val, -1);
 				lst = g_list_prepend (lst, (gpointer) val);
 				rb_property_view_set_selection (view, lst);
+				g_free (val);
 			}
 		}
 		g_signal_emit (G_OBJECT (view), rb_property_view_signals[SHOW_POPUP], 0);
Index: widgets/rb-query-creator.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/rb-query-creator.c,v
retrieving revision 1.41
diff -p -u -r1.41 rb-query-creator.c
--- widgets/rb-query-creator.c	17 Jul 2006 14:52:55 -0000	1.41
+++ widgets/rb-query-creator.c	21 Jul 2006 21:31:37 -0000
@@ -1,4 +1,5 @@
-/*
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
  *  arch-tag: Implementation of RhythmDB query creation dialog
  *
  *  Copyright (C) 2003, 2004 Colin Walters <walters@gnome.org>
@@ -140,7 +141,8 @@ rb_query_creator_init (RBQueryCreator *c
 }
 
 static GObject *
-rb_query_creator_constructor (GType type, guint n_construct_properties,
+rb_query_creator_constructor (GType type,
+                              guint n_construct_properties,
 			      GObjectConstructParam *construct_properties)
 {
 	RBQueryCreatorPrivate *priv;
@@ -270,9 +272,9 @@ rb_query_creator_set_property (GObject *
 
 static void
 rb_query_creator_get_property (GObject *object,
-			      guint prop_id,
-			      GValue *value,
-			      GParamSpec *pspec)
+                               guint prop_id,
+                               GValue *value,
+                               GParamSpec *pspec)
 {
 	RBQueryCreator *creator = RB_QUERY_CREATOR (object);
 	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
@@ -298,8 +300,10 @@ rb_query_creator_new (RhythmDB *db)
 }
 
 static gboolean
-rb_query_creator_load_query (RBQueryCreator *creator, GPtrArray *query,
-			     RhythmDBQueryModelLimitType limit_type, GValueArray *limit_value)
+rb_query_creator_load_query (RBQueryCreator *creator,
+                             GPtrArray *query,
+			     RhythmDBQueryModelLimitType limit_type,
+                             GValueArray *limit_value)
 {
 	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
 	int i;
@@ -398,7 +402,9 @@ rb_query_creator_load_query (RBQueryCrea
 }
 
 static gboolean
-rb_query_creator_set_sorting (RBQueryCreator *creator, const char *sort_column, gint sort_direction)
+rb_query_creator_set_sorting (RBQueryCreator *creator,
+                              const char *sort_column,
+                              gint sort_direction)
 {
 	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
 	int i;
@@ -421,11 +427,13 @@ rb_query_creator_set_sorting (RBQueryCre
 
 	gtk_option_menu_set_history (GTK_OPTION_MENU (priv->sort_menu), i);
 	sort_option_menu_changed (GTK_OPTION_MENU (priv->sort_menu), creator); /* force the checkbox to change label */
+
 	return TRUE;
 }
 
 GtkWidget *
-rb_query_creator_new_from_query (RhythmDB *db, GPtrArray *query,
+rb_query_creator_new_from_query (RhythmDB *db,
+                                 GPtrArray *query,
 				 RhythmDBQueryModelLimitType limit_type,
                                  GValueArray *limit_value,
 				 const char *sort_column,
@@ -484,12 +492,16 @@ get_entry_for_property (RBQueryCreator *
 GPtrArray *
 rb_query_creator_get_query (RBQueryCreator *creator)
 {
-	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
+	RBQueryCreatorPrivate *priv;
 	GPtrArray *query;
 	GPtrArray *sub_query;
 	GList *rows, *row;
 	gboolean disjunction;
 
+	g_return_val_if_fail (RB_IS_QUERY_CREATOR (creator), NULL);
+
+	priv = QUERY_CREATOR_GET_PRIVATE (creator);
+
 	disjunction = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->disjunction_check));
 	sub_query = g_ptr_array_new ();
 	rows = priv->rows;
@@ -530,17 +542,22 @@ rb_query_creator_get_query (RBQueryCreat
 				      RHYTHMDB_PROP_TYPE,
 				      RHYTHMDB_ENTRY_TYPE_SONG,
 				      /* the constructed query */
-			       RHYTHMDB_QUERY_SUBQUERY,
-			       sub_query,
-			       RHYTHMDB_QUERY_END);
+                                      RHYTHMDB_QUERY_SUBQUERY,
+                                      sub_query,
+                                      RHYTHMDB_QUERY_END);
 	return query;
 }
 
 void
 rb_query_creator_get_limit (RBQueryCreator *creator,
-			    RhythmDBQueryModelLimitType *type, GValueArray **limit)
+			    RhythmDBQueryModelLimitType *type,
+                            GValueArray **limit)
 {
-	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
+	RBQueryCreatorPrivate *priv;
+
+	g_return_if_fail (RB_IS_QUERY_CREATOR (creator));
+
+	priv = QUERY_CREATOR_GET_PRIVATE (creator);
 
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->limit_check))) {
 		guint64 l;
@@ -578,22 +595,33 @@ rb_query_creator_get_limit (RBQueryCreat
 }
 
 void
-rb_query_creator_get_sort_order (RBQueryCreator *creator, const char **sort_column, gint *sort_direction)
+rb_query_creator_get_sort_order (RBQueryCreator *creator,
+                                 const char **sort_column,
+                                 gint *sort_direction)
 {
-	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
-	int i;
+	RBQueryCreatorPrivate *priv;
 
-	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->sort_desc)))
-		*sort_direction = GTK_SORT_DESCENDING;
-	else
-		*sort_direction = GTK_SORT_ASCENDING;
+	g_return_if_fail (RB_IS_QUERY_CREATOR (creator));
 
-	i = gtk_option_menu_get_history (GTK_OPTION_MENU (priv->sort_menu));
-	*sort_column = sort_options[i].sort_key;
+	priv = QUERY_CREATOR_GET_PRIVATE (creator);
+
+	if (sort_direction != NULL) {
+		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->sort_desc)))
+			*sort_direction = GTK_SORT_DESCENDING;
+		else
+			*sort_direction = GTK_SORT_ASCENDING;
+	}
+
+	if (sort_column != NULL) {
+		int i;
+		i = gtk_option_menu_get_history (GTK_OPTION_MENU (priv->sort_menu));
+		*sort_column = sort_options[i].sort_key;
+	}
 }
 
 static void
-limit_toggled_cb (GtkWidget *limit, RBQueryCreator *creator)
+limit_toggled_cb (GtkWidget *limit,
+                  RBQueryCreator *creator)
 {
 	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
 	gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (limit));
@@ -606,7 +634,8 @@ limit_toggled_cb (GtkWidget *limit, RBQu
 }
 
 static GtkWidget *
-lookup_row_by_widget (RBQueryCreator *creator, GtkWidget *widget)
+lookup_row_by_widget (RBQueryCreator *creator,
+                      GtkWidget *widget)
 {
 	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
 	GList *rows = priv->rows;
@@ -627,7 +656,8 @@ lookup_row_by_widget (RBQueryCreator *cr
 }
 
 static void
-remove_button_click_cb (GtkWidget *button, RBQueryCreator *creator)
+remove_button_click_cb (GtkWidget *button,
+                        RBQueryCreator *creator)
 {
 	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
 	GtkWidget *row;
@@ -640,7 +670,8 @@ remove_button_click_cb (GtkWidget *butto
 }
 
 static void
-add_button_click_cb (GtkWidget *button, RBQueryCreator *creator)
+add_button_click_cb (GtkWidget *button,
+                     RBQueryCreator *creator)
 {
 	append_row (creator);
 }
@@ -780,7 +811,7 @@ property_option_menu_changed (GtkOptionM
 
 static GtkWidget*
 create_property_option_menu (RBQueryCreator *creator,
-			    const RBQueryCreatorPropertyOption *options,
+                             const RBQueryCreatorPropertyOption *options,
 			     int length)
 {
 	GtkWidget *option_menu;
Index: widgets/rb-song-info.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/rb-song-info.c,v
retrieving revision 1.68
diff -p -u -r1.68 rb-song-info.c
--- widgets/rb-song-info.c	17 Jul 2006 14:52:55 -0000	1.68
+++ widgets/rb-song-info.c	21 Jul 2006 21:31:37 -0000
@@ -353,12 +353,14 @@ rb_song_info_constructor (GType type, gu
 
 	g_return_val_if_fail (selected_entries != NULL, NULL);
 
-	for (tem = selected_entries; tem; tem = tem->next)
+	for (tem = selected_entries; tem; tem = tem->next) {
 		if (!rhythmdb_entry_is_editable (song_info->priv->db,
 						 selected_entries->data)) {
 			editable = FALSE;
 			break;
 		}
+	}
+
 	song_info->priv->editable = editable;
 
 	if (selected_entries->next == NULL) {
@@ -477,7 +479,7 @@ rb_song_info_finalize (GObject *object)
 
 	g_return_if_fail (song_info->priv != NULL);
 
-	g_signal_handlers_disconnect_by_func (G_OBJECT (song_info->priv->source),
+	g_signal_handlers_disconnect_by_func (song_info->priv->source,
 					      G_CALLBACK (rb_song_info_query_model_changed_cb),
 					      song_info);
 
@@ -485,9 +487,9 @@ rb_song_info_finalize (GObject *object)
 	g_object_unref (song_info->priv->artists);
 	g_object_unref (song_info->priv->genres);
 
-	g_object_unref (G_OBJECT (song_info->priv->db));
-	g_object_unref (G_OBJECT (song_info->priv->source));
-	g_object_unref (G_OBJECT (song_info->priv->query_model));
+	g_object_unref (song_info->priv->db);
+	g_object_unref (song_info->priv->source);
+	g_object_unref (song_info->priv->query_model);
 
 	if (song_info->priv->selected_entries != NULL) {
 		g_list_foreach (song_info->priv->selected_entries, (GFunc)rhythmdb_entry_unref, NULL);
@@ -986,9 +988,8 @@ rb_song_info_backward_clicked_cb (GtkWid
 	RhythmDBEntry *new_entry;
 
 	rb_song_info_sync_entries (RB_SONG_INFO (song_info));
-	new_entry =
-		rhythmdb_query_model_get_previous_from_entry (song_info->priv->query_model,
-							      song_info->priv->current_entry);
+	new_entry = rhythmdb_query_model_get_previous_from_entry (song_info->priv->query_model,
+								  song_info->priv->current_entry);
 	g_return_if_fail (new_entry != NULL);
 
 	song_info->priv->current_entry = new_entry;
@@ -997,6 +998,7 @@ rb_song_info_backward_clicked_cb (GtkWid
 
 	rb_song_info_populate_dialog (song_info);
 	g_object_notify (G_OBJECT (song_info), "current-entry");
+	rhythmdb_entry_unref (new_entry);
 }
 
 static void
@@ -1006,9 +1008,8 @@ rb_song_info_forward_clicked_cb (GtkWidg
 	RhythmDBEntry *new_entry;
 
 	rb_song_info_sync_entries (RB_SONG_INFO (song_info));
-	new_entry =
-		rhythmdb_query_model_get_next_from_entry (song_info->priv->query_model,
-							  song_info->priv->current_entry);
+	new_entry = rhythmdb_query_model_get_next_from_entry (song_info->priv->query_model,
+							      song_info->priv->current_entry);
 	g_return_if_fail (new_entry != NULL);
 
 	song_info->priv->current_entry = new_entry;
@@ -1017,6 +1018,8 @@ rb_song_info_forward_clicked_cb (GtkWidg
 
 	rb_song_info_populate_dialog (song_info);
 	g_object_notify (G_OBJECT (song_info), "current-entry");
+
+	rhythmdb_entry_unref (new_entry);
 }
 
 /*
@@ -1038,11 +1041,14 @@ rb_song_info_update_buttons (RBSongInfo 
 							      song_info->priv->current_entry);
 
 	gtk_widget_set_sensitive (song_info->priv->backward, entry != NULL);
+	rhythmdb_entry_unref (entry);
+
 	/* forward */
 	entry = rhythmdb_query_model_get_next_from_entry (song_info->priv->query_model,
 							  song_info->priv->current_entry);
 
 	gtk_widget_set_sensitive (song_info->priv->forward, entry != NULL);
+	rhythmdb_entry_unref (entry);
 }
 
 static void
@@ -1140,7 +1146,7 @@ rb_song_info_update_rating (RBSongInfo *
 	g_return_if_fail (RB_IS_SONG_INFO (song_info));
 
 	rating = rhythmdb_entry_get_double (song_info->priv->current_entry, RHYTHMDB_PROP_RATING);
-	g_object_set (G_OBJECT (song_info->priv->rating),
+	g_object_set (song_info->priv->rating,
 		      "rating", rating,
 		      NULL);
 }
@@ -1315,7 +1321,7 @@ rb_song_info_sync_entry_single (RBSongIn
 	discnum_str = gtk_entry_get_text (GTK_ENTRY (dialog->priv->disc_cur));
 	year_str = gtk_entry_get_text (GTK_ENTRY (dialog->priv->year));
 
-	g_signal_emit (G_OBJECT (dialog), rb_song_info_signals[PRE_METADATA_CHANGE], 0,
+	g_signal_emit (dialog, rb_song_info_signals[PRE_METADATA_CHANGE], 0,
 		       entry);
 
 	tracknum = g_ascii_strtoull (tracknum_str, &endptr, 10);
