diff --git a/camel/camel-db.c b/camel/camel-db.c
index 55b4557..3bb1a11 100644
--- a/camel/camel-db.c
+++ b/camel/camel-db.c
@@ -612,7 +612,7 @@ camel_db_get_folder_uids_flags (CamelDB *db, char *folder_name, char *sort_by, c
 	 sqlite3_free (sel_query);
 
 	 for (i=0; i<uids->len; i++) {
-		 g_hash_table_insert (table, uids->pdata[i], flags->pdata[i]);
+		 g_hash_table_insert (table, camel_pstring_strdup(uids->pdata[i]), flags->pdata[i]);
 	 }
 
 	 g_ptr_array_free (flags, TRUE);
diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index c2e6d55..dc36cbb 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -155,7 +155,7 @@ camel_folder_summary_init (CamelFolderSummary *s)
 
 	s->message_info_size = sizeof(CamelMessageInfoBase);
 	s->content_info_size = sizeof(CamelMessageContentInfo);
-	p->flag_cache = g_hash_table_new (g_str_hash, g_str_equal);
+	p->flag_cache = g_hash_table_new_full (g_str_hash, g_str_equal, camel_pstring_free, NULL);
 
 	s->message_info_chunks = NULL;
 	s->content_info_chunks = NULL;
@@ -4650,7 +4651,7 @@ info_set_flags(CamelMessageInfo *info, guint32 flags, guint32 set)
 			mi->summary->visible_count -= junk ? junk : deleted;
 	}
 	if (mi->uid)
-		g_hash_table_replace (_PRIVATE(mi->summary)->flag_cache, (char *)mi->uid, GUINT_TO_POINTER(mi->flags));
+		g_hash_table_replace (_PRIVATE(mi->summary)->flag_cache, (char *)camel_pstring_strdup(mi->uid), GUINT_TO_POINTER(mi->flags));
 	if (mi->summary && mi->summary->folder && mi->uid) {
 		CamelFolderChangeInfo *changes = camel_folder_change_info_new();
 
