summaryrefslogtreecommitdiff
path: root/libcaja-private/caja-undostack-manager.c
diff options
context:
space:
mode:
authorMonsta <[email protected]>2014-12-03 16:05:43 +0300
committerinfirit <[email protected]>2014-12-10 10:38:37 +0100
commit523ca6754f1f1f5e86367c644bb721b20f5fbebd (patch)
treec34b3bae093a37a7d7594cc4efa3168726ce5340 /libcaja-private/caja-undostack-manager.c
parent78661bd703b26343621b209f4f13e5e9fcbad802 (diff)
downloadcaja-523ca6754f1f1f5e86367c644bb721b20f5fbebd.tar.bz2
caja-523ca6754f1f1f5e86367c644bb721b20f5fbebd.tar.xz
libcaja-private: don't leak memory
Diffstat (limited to 'libcaja-private/caja-undostack-manager.c')
-rw-r--r--libcaja-private/caja-undostack-manager.c62
1 files changed, 24 insertions, 38 deletions
diff --git a/libcaja-private/caja-undostack-manager.c b/libcaja-private/caja-undostack-manager.c
index 5686abfa..16f977f3 100644
--- a/libcaja-private/caja-undostack-manager.c
+++ b/libcaja-private/caja-undostack-manager.c
@@ -2034,66 +2034,52 @@ get_uri_parent_path (char *uri)
static GHashTable *
retrieve_files_to_restore (GHashTable * trashed)
{
- GFileEnumerator *enumerator;
- GFileInfo *info;
- GFile *trash;
- GFile *item;
- guint64 mtime_item;
- guint64 *mtime;
- const char *origpath;
- GFile *origfile;
- char *origuri;
- gpointer lookupvalue;
- GHashTable *to_restore;
-
- to_restore =
- g_hash_table_new_full (g_direct_hash,
- g_direct_equal, g_object_unref, g_free);
+ if (!(g_hash_table_size (trashed)) > 0) {
+ return NULL;
+ }
- trash = g_file_new_for_uri ("trash:");
+ GFile *trash = g_file_new_for_uri ("trash:");
- enumerator = g_file_enumerate_children (trash,
+ GFileEnumerator *enumerator = g_file_enumerate_children (trash,
G_FILE_ATTRIBUTE_STANDARD_NAME
","
G_FILE_ATTRIBUTE_TIME_MODIFIED
",trash::orig-path", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, FALSE, NULL);
- mtime = 0;
-
- guint nb;
- GList *l;
- if (!(g_hash_table_size (trashed)) > 0)
- return NULL;
-
+ GHashTable *to_restore = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal, g_object_unref, g_free);
+
if (enumerator) {
- while ((info =
- g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
+ GFileInfo *info;
+ while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
/* Retrieve the original file uri */
- origpath = g_file_info_get_attribute_byte_string (info, "trash::orig-path");
- origfile = g_file_new_for_path (origpath);
- origuri = g_file_get_uri (origfile);
+ const char *origpath = g_file_info_get_attribute_byte_string (info, "trash::orig-path");
+ GFile *origfile = g_file_new_for_path (origpath);
+ char *origuri = g_file_get_uri (origfile);
g_object_unref (origfile);
- lookupvalue = g_hash_table_lookup (trashed, origuri);
+ gboolean origuri_inserted = FALSE;
+ gpointer lookupvalue = g_hash_table_lookup (trashed, origuri);
if (lookupvalue) {
- mtime = (guint64 *)
- lookupvalue;
- mtime_item =
- g_file_info_get_attribute_uint64
- (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ guint64 *mtime = (guint64 *) lookupvalue;
+ guint64 mtime_item = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
if (*mtime == mtime_item) {
- item = g_file_get_child (trash, g_file_info_get_name (info)); /* File in the trash */
+ GFile *item = g_file_get_child (trash, g_file_info_get_name (info)); /* File in the trash */
g_hash_table_insert (to_restore, item, origuri);
+ origuri_inserted = TRUE;
}
- } else {
- g_free (origuri);
}
+ if (!origuri_inserted) {
+ g_free (origuri);
+ }
}
+
g_file_enumerator_close (enumerator, FALSE, NULL);
g_object_unref (enumerator);
}
+
g_object_unref (trash);
return to_restore;