diff -up glib2/glib/gkeyfile.c glib/glib/gkeyfile.c
--- glib2/glib/gkeyfile.c	2010-11-07 14:18:37.585209579 -0200
+++ glib/glib/gkeyfile.c	2010-11-07 15:21:17.527208511 -0200
@@ -1338,8 +1338,22 @@ g_key_file_set_value (GKeyFile    *key_f
         g_key_file_add_key (key_file, group, key, value);
       else
         {
-          g_free (pair->value);
-          pair->value = g_strdup (value);
+	  GError *remove_error = NULL;
+	  group = NULL;
+	  g_key_file_remove_key(key_file, group_name, key, &remove_error);
+
+	  group = g_key_file_lookup_group (key_file, group_name);
+
+	  if (!group)
+    	  {
+		g_key_file_add_group (key_file, group_name);
+	      	group = (GKeyFileGroup *) key_file->groups->data;
+	  }
+
+	  g_key_file_add_key (key_file, group, key, value);
+
+	  if (remove_error)
+           g_error_free(remove_error);
         }
     }
 }
