summaryrefslogtreecommitdiff
path: root/libcaja-private
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
parent78661bd703b26343621b209f4f13e5e9fcbad802 (diff)
downloadcaja-523ca6754f1f1f5e86367c644bb721b20f5fbebd.tar.bz2
caja-523ca6754f1f1f5e86367c644bb721b20f5fbebd.tar.xz
libcaja-private: don't leak memory
Diffstat (limited to 'libcaja-private')
-rw-r--r--libcaja-private/caja-emblem-utils.c3
-rw-r--r--libcaja-private/caja-file-conflict-dialog.c5
-rw-r--r--libcaja-private/caja-file-utilities.c13
-rw-r--r--libcaja-private/caja-link.c21
-rw-r--r--libcaja-private/caja-undostack-manager.c62
5 files changed, 43 insertions, 61 deletions
diff --git a/libcaja-private/caja-emblem-utils.c b/libcaja-private/caja-emblem-utils.c
index f837df69..951887aa 100644
--- a/libcaja-private/caja-emblem-utils.c
+++ b/libcaja-private/caja-emblem-utils.c
@@ -395,7 +395,6 @@ caja_emblem_remove_emblem (const char *keyword)
struct stat stat_buf;
struct utimbuf ubuf;
-
dir = g_strdup_printf ("%s/.icons/hicolor/48x48/emblems",
g_get_home_dir ());
stat_dir = g_strdup_printf ("%s/.icons/hicolor",
@@ -425,6 +424,8 @@ caja_emblem_remove_emblem (const char *keyword)
return FALSE;
}
+ g_free (path);
+
/* Touch the toplevel dir */
if (stat (stat_dir, &stat_buf) == 0)
{
diff --git a/libcaja-private/caja-file-conflict-dialog.c b/libcaja-private/caja-file-conflict-dialog.c
index d78f961d..8b8dce74 100644
--- a/libcaja-private/caja-file-conflict-dialog.c
+++ b/libcaja-private/caja-file-conflict-dialog.c
@@ -340,8 +340,9 @@ file_list_ready_cb (GList *files,
gtk_widget_hide (details->diff_button);
if (!source_is_dir && !dest_is_dir)
{
- if (g_find_program_in_path ("meld")) {
-
+ gchar *meld_found = g_find_program_in_path ("meld");
+ if (meld_found) {
+ g_free (meld_found);
gboolean src_is_binary;
gboolean dest_is_binary;
diff --git a/libcaja-private/caja-file-utilities.c b/libcaja-private/caja-file-utilities.c
index cc08be57..dd8b449c 100644
--- a/libcaja-private/caja-file-utilities.c
+++ b/libcaja-private/caja-file-utilities.c
@@ -1107,18 +1107,13 @@ caja_find_file_insensitive_next (GFile *parent, const gchar *name)
gboolean
caja_is_engrampa_installed (void)
{
- static int installed = - 1;
+ static int installed = -1;
if (installed < 0)
{
- if (g_find_program_in_path ("engrampa"))
- {
- installed = 1;
- }
- else
- {
- installed = 0;
- }
+ gchar *found = g_find_program_in_path ("engrampa");
+ installed = found ? 1 : 0;
+ g_free (found);
}
return installed > 0 ? TRUE : FALSE;
diff --git a/libcaja-private/caja-link.c b/libcaja-private/caja-link.c
index 89971772..4f39a474 100644
--- a/libcaja-private/caja-link.c
+++ b/libcaja-private/caja-link.c
@@ -416,19 +416,14 @@ caja_link_local_get_additional_text (const char *path)
static char *
caja_link_get_link_uri_from_desktop (GKeyFile *key_file, const char *desktop_file_uri)
{
- GFile *file, *parent;
- char *type;
- char *retval;
- char *scheme;
-
- retval = NULL;
-
- type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
+ char *type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
if (type == NULL)
{
return NULL;
}
+ char *retval = NULL;
+
if (strcmp (type, "URL") == 0)
{
/* Some old broken desktop files use this nonstandard feature, we need handle it though */
@@ -450,11 +445,11 @@ caja_link_get_link_uri_from_desktop (GKeyFile *key_file, const char *desktop_fil
* g_file_parse_name(), but it does not know how to resolve
* relative file names, since the base directory is unknown.
*/
- scheme = g_uri_parse_scheme (retval);
+ char *scheme = g_uri_parse_scheme (retval);
if (scheme == NULL)
{
- file = g_file_new_for_uri (desktop_file_uri);
- parent = g_file_get_parent (file);
+ GFile *file = g_file_new_for_uri (desktop_file_uri);
+ GFile *parent = g_file_get_parent (file);
g_object_unref (file);
if (parent != NULL)
@@ -466,6 +461,10 @@ caja_link_get_link_uri_from_desktop (GKeyFile *key_file, const char *desktop_fil
g_object_unref (parent);
}
}
+ else
+ {
+ g_free (scheme);
+ }
}
return retval;
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;