diff options
author | Gaël Bonithon <gael@xfce.org> | 2021-12-24 23:25:16 +0100 |
---|---|---|
committer | Gaël Bonithon <gael@xfce.org> | 2021-12-26 18:29:15 +0100 |
commit | b014aabd2d78472a18a9b863e51dd6f1631d78cb (patch) | |
tree | e966db49d789ff0d514d443f5f1fa1f725497fc1 /plugins | |
parent | 851a63ce087fe27c23bc625c25a4c0a9c976e895 (diff) | |
download | tumbler-b014aabd2d78472a18a9b863e51dd6f1631d78cb.tar.gz |
Cleanup: Use `g_file_peek_path()` when appropriate
This simplifies the code, fixes leaks in `g_debug()` calls, and
GLib 2.56 will be required when moving to Xfce 4.18.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c | 18 | ||||
-rw-r--r-- | plugins/desktop-thumbnailer/desktop-thumbnailer.c | 15 | ||||
-rw-r--r-- | plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c | 5 | ||||
-rw-r--r-- | plugins/gepub-thumbnailer/gepub-thumbnailer.c | 7 | ||||
-rw-r--r-- | plugins/jpeg-thumbnailer/jpeg-thumbnailer.c | 7 | ||||
-rw-r--r-- | plugins/odf-thumbnailer/odf-thumbnailer.c | 7 | ||||
-rw-r--r-- | plugins/raw-thumbnailer/raw-thumbnailer.c | 5 | ||||
-rw-r--r-- | plugins/xdg-cache/xdg-cache-cache.c | 20 | ||||
-rw-r--r-- | plugins/xdg-cache/xdg-cache-thumbnail.c | 30 |
9 files changed, 32 insertions, 82 deletions
diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c b/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c index e76e405..a942ef2 100644 --- a/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c +++ b/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c @@ -101,14 +101,14 @@ desktop_thumbnailer_get_from_desktop_file (GFile *file, DesktopThumbnailer *thumbnailer; GKeyFile *key_file; GError *error = NULL; - gchar *filename; + const gchar *filename; gchar *exec; gchar **mime_types; g_return_val_if_fail (G_IS_FILE (file), NULL); /* determine the absolute filename of the input file */ - filename = g_file_get_path (file); + filename = g_file_peek_path (file); /* allocate a new key file object */ key_file = g_key_file_new (); @@ -118,9 +118,7 @@ desktop_thumbnailer_get_from_desktop_file (GFile *file, { g_warning (TUMBLER_WARNING_LOAD_FILE_FAILED, filename, error->message); g_clear_error (&error); - g_key_file_free (key_file); - g_free (filename); return NULL; } @@ -132,9 +130,7 @@ desktop_thumbnailer_get_from_desktop_file (GFile *file, { g_warning (TUMBLER_WARNING_MALFORMED_FILE, filename, error->message); g_clear_error (&error); - g_key_file_free (key_file); - g_free (filename); return NULL; } @@ -146,10 +142,8 @@ desktop_thumbnailer_get_from_desktop_file (GFile *file, { g_warning (TUMBLER_WARNING_MALFORMED_FILE, filename, error->message); g_clear_error (&error); - g_free (exec); g_key_file_free (key_file); - g_free (filename); return NULL; } @@ -164,7 +158,6 @@ desktop_thumbnailer_get_from_desktop_file (GFile *file, g_print("Registered thumbnailer %s\n", exec); g_free(exec); - g_free (filename); return thumbnailer; } @@ -175,15 +168,10 @@ desktop_thumbnailer_get_thumbnailers_from_dir (GList *thumbnailers, GStrv uri_schemes) { const gchar *base_name; - gchar *dirname; GDir *dir; - /* determine the absolute path to the directory */ - dirname = g_file_get_path (directory); - /* try to open the directory for reading */ - dir = g_dir_open (dirname, 0, NULL); - g_free (dirname); + dir = g_dir_open (g_file_peek_path (directory), 0, NULL); if (dir == NULL) return thumbnailers; diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer.c b/plugins/desktop-thumbnailer/desktop-thumbnailer.c index 4faa77e..5e79543 100644 --- a/plugins/desktop-thumbnailer/desktop-thumbnailer.c +++ b/plugins/desktop-thumbnailer/desktop-thumbnailer.c @@ -265,7 +265,7 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer, GFile *tmpfile; gchar *exec; gchar **cmd_argv; - gchar *tmpfilepath; + const gchar *tmpfilepath; gboolean res; gint cmd_argc; gint size; @@ -278,7 +278,7 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer, if ( G_LIKELY (tmpfile) ) { - tmpfilepath = g_file_get_path (tmpfile); + tmpfilepath = g_file_peek_path (tmpfile); size = MIN (width, height); @@ -322,7 +322,6 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer, else g_warning ("Malformed command line \"%s\": %s", exec, (*error)->message); - g_free (tmpfilepath); g_object_unref (tmpfile); g_object_unref (stream); } @@ -344,7 +343,6 @@ desktop_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, TumblerThumbnailFlavor *flavor; TumblerImageData data; const gchar *uri; - gchar *path; GFile *file; gint height; gint width; @@ -360,9 +358,7 @@ desktop_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, return; uri = tumbler_file_info_get_uri (info); - file = g_file_new_for_uri (uri); - path = g_file_get_path (file); thumbnail = tumbler_file_info_get_thumbnail (info); g_assert (thumbnail != NULL); @@ -372,8 +368,9 @@ desktop_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, tumbler_thumbnail_flavor_get_size (flavor, &width, &height); - pixbuf = desktop_thumbnailer_load_thumbnail (DESKTOP_THUMBNAILER(thumbnailer), - uri, path, width, height, cancellable, &error); + pixbuf = desktop_thumbnailer_load_thumbnail (DESKTOP_THUMBNAILER (thumbnailer), + uri, g_file_peek_path (file), + width, height, cancellable, &error); if (pixbuf != NULL) { @@ -402,8 +399,6 @@ desktop_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, g_signal_emit_by_name (thumbnailer, "ready", uri); } - g_free (path); - g_object_unref (thumbnail); g_object_unref (flavor); g_object_unref (file); diff --git a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c index 795ab92..f8c7cbb 100644 --- a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c +++ b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c @@ -185,6 +185,7 @@ ffmpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, /* get the local absolute path to the source file */ file = g_file_new_for_uri (uri); path = g_file_get_path (file); + g_object_unref (file); if (path == NULL) { @@ -195,12 +196,10 @@ ffmpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, g_error_free (error); /* clean up */ - g_object_unref (file); g_object_unref (thumbnail); video_thumbnailer_destroy_image_data (v_data); return; } - g_object_unref (file); /* try to generate a thumbnail */ if (video_thumbnailer_generate_thumbnail_to_buffer (ffmpeg_thumbnailer->video, path, v_data) != 0) @@ -217,7 +216,7 @@ ffmpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, video_thumbnailer_destroy_image_data (v_data); return; } - g_free (path); + g_free (path); v_stream = g_memory_input_stream_new_from_data (v_data->image_data_ptr, v_data->image_data_size, NULL); diff --git a/plugins/gepub-thumbnailer/gepub-thumbnailer.c b/plugins/gepub-thumbnailer/gepub-thumbnailer.c index 775a5aa..b019020 100644 --- a/plugins/gepub-thumbnailer/gepub-thumbnailer.c +++ b/plugins/gepub-thumbnailer/gepub-thumbnailer.c @@ -145,7 +145,6 @@ gepub_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, const gchar *uri; GFile *file; GError *error = NULL; - gchar *path; GdkPixbuf *pixbuf = NULL; GepubDoc *doc; gchar *cover; @@ -166,15 +165,13 @@ gepub_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, if (g_file_is_native (file)) { /* try to load the EPUB file */ - path = g_file_get_path (file); - doc = gepub_doc_new (path, &error); + doc = gepub_doc_new (g_file_peek_path (file), &error); if (error != NULL) { g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message); g_error_free (error); - g_free (path); g_object_unref (file); return; } @@ -190,7 +187,6 @@ gepub_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, "Cover not found"); g_free (cover); - g_free (path); g_object_unref (doc); g_object_unref (file); return; @@ -224,7 +220,6 @@ gepub_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, g_bytes_unref (content); g_free (cover_mime); - g_free (path); g_object_unref (doc); g_object_unref (thumbnail); } diff --git a/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c b/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c index c137458..f89128d 100644 --- a/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c +++ b/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c @@ -786,7 +786,6 @@ jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, JOCTET *content; GError *error = NULL; GFile *file; - gchar *path; gsize length; gint fd; gint height; @@ -818,10 +817,8 @@ jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, #ifdef HAVE_MMAP if (g_file_is_native (file)) { - path = g_file_get_path (file); - /* try to open the file at the given path */ - fd = open (path, O_RDONLY); + fd = open (g_file_peek_path (file), O_RDONLY); if (G_LIKELY (fd >= 0)) { /* determine the status of the file */ @@ -872,8 +869,6 @@ jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, /* close the file */ close (fd); } - - g_free (path); } #endif diff --git a/plugins/odf-thumbnailer/odf-thumbnailer.c b/plugins/odf-thumbnailer/odf-thumbnailer.c index d231aac..629d8ee 100644 --- a/plugins/odf-thumbnailer/odf-thumbnailer.c +++ b/plugins/odf-thumbnailer/odf-thumbnailer.c @@ -272,7 +272,6 @@ odf_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, const gchar *uri; GFile *file; GError *error = NULL; - gchar *path; GsfInfile *infile; GdkPixbuf *pixbuf = NULL; TumblerImageData data; @@ -291,9 +290,7 @@ odf_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, if (g_file_is_native (file)) { /* try to mmap the file */ - path = g_file_get_path (file); - input = gsf_input_mmap_new (path, NULL); - g_free (path); + input = gsf_input_mmap_new (g_file_peek_path (file), NULL); } if (input == NULL) @@ -304,6 +301,7 @@ odf_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, { g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message); g_error_free (error); + g_object_unref (file); return; } } @@ -362,6 +360,7 @@ odf_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, g_signal_emit_by_name (thumbnailer, "ready", uri); } + g_object_unref (file); g_object_unref (input); g_object_unref (thumbnail); } diff --git a/plugins/raw-thumbnailer/raw-thumbnailer.c b/plugins/raw-thumbnailer/raw-thumbnailer.c index 8daf9e9..16c75da 100644 --- a/plugins/raw-thumbnailer/raw-thumbnailer.c +++ b/plugins/raw-thumbnailer/raw-thumbnailer.c @@ -108,7 +108,7 @@ raw_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, TumblerImageData data; TumblerThumbnail *thumbnail; const gchar *uri; - gchar *path; + const gchar *path; GdkPixbuf *pixbuf = NULL; GError *error = NULL; GFile *file; @@ -137,7 +137,7 @@ raw_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, g_object_unref (flavor); /* libopenraw only handles local IO */ - path = g_file_get_path (file); + path = g_file_peek_path (file); if (path != NULL && g_path_is_absolute (path)) { pixbuf = or_gdkpixbuf_extract_rotated_thumbnail (path, MIN (width, height)); @@ -154,7 +154,6 @@ raw_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, TUMBLER_ERROR_MESSAGE_LOCAL_ONLY); } - g_free (path); g_object_unref (file); if (pixbuf != NULL) diff --git a/plugins/xdg-cache/xdg-cache-cache.c b/plugins/xdg-cache/xdg-cache-cache.c index 69a07e6..f32c1f5 100644 --- a/plugins/xdg-cache/xdg-cache-cache.c +++ b/plugins/xdg-cache/xdg-cache-cache.c @@ -275,14 +275,12 @@ xdg_cache_cache_cleanup (TumblerCache *cache, { base_file = xdg_cache_cache_get_file (base_uris[n], iter->data); - filename = g_file_get_path (base_file); + filename = (gchar *) g_file_peek_path (base_file); if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { g_unlink (filename); } - g_free(filename); - /* releas the base file */ g_object_unref(base_file); } @@ -327,9 +325,8 @@ xdg_cache_cache_copy_or_move_file (TumblerCache *cache, { GFile *from_file; GFile *temp_file; - gchar *temp_path; - gchar *dest_path; - gchar *from_path; + const gchar *temp_path; + const gchar *dest_path; gboolean result; GFile *dest_file; @@ -349,33 +346,28 @@ xdg_cache_cache_copy_or_move_file (TumblerCache *cache, if (result) { - temp_path = g_file_get_path (temp_file); + temp_path = g_file_peek_path (temp_file); if (xdg_cache_cache_write_thumbnail_info (temp_path, to_uri, mtime, NULL, NULL)) { dest_file = xdg_cache_cache_get_file (to_uri, flavor); - dest_path = g_file_get_path (dest_file); + dest_path = g_file_peek_path (dest_file); if (g_rename (temp_path, dest_path) != 0) g_unlink (temp_path); - g_free (dest_path); g_object_unref (dest_file); } else { g_unlink (temp_path); } - - g_free (temp_path); } else if (!do_copy) { /* if the move failed, drop the old cache file */ - from_path = g_file_get_path (from_file); - g_unlink (from_path); - g_free (from_path); + g_unlink (g_file_peek_path (from_file)); } g_object_unref (temp_file); diff --git a/plugins/xdg-cache/xdg-cache-thumbnail.c b/plugins/xdg-cache/xdg-cache-thumbnail.c index 7b22f33..e58b2ea 100644 --- a/plugins/xdg-cache/xdg-cache-thumbnail.c +++ b/plugins/xdg-cache/xdg-cache-thumbnail.c @@ -228,7 +228,6 @@ xdg_cache_thumbnail_load (TumblerThumbnail *thumbnail, XDGCacheThumbnail *cache_thumbnail = XDG_CACHE_THUMBNAIL (thumbnail); GError *err = NULL; GFile *file; - gchar *path; g_return_val_if_fail (XDG_CACHE_IS_THUMBNAIL (thumbnail), FALSE); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); @@ -238,20 +237,16 @@ xdg_cache_thumbnail_load (TumblerThumbnail *thumbnail, file = xdg_cache_cache_get_file (cache_thumbnail->uri, cache_thumbnail->flavor); - path = g_file_get_path (file); - g_object_unref (file); g_free (cache_thumbnail->cached_uri); cache_thumbnail->cached_uri = NULL; cache_thumbnail->cached_mtime = 0; - xdg_cache_cache_read_thumbnail_info (path, + xdg_cache_cache_read_thumbnail_info (g_file_peek_path (file), &cache_thumbnail->cached_uri, &cache_thumbnail->cached_mtime, cancellable, &err); - - /* free the filename */ - g_free (path); + g_object_unref (file); if (err != NULL) { @@ -342,9 +337,8 @@ xdg_cache_thumbnail_save_image_data (TumblerThumbnail *thumbnail, GFile *dest_file; GFile *flavor_dir; GFile *temp_file; - gchar *dest_path; - gchar *flavor_dir_path; - gchar *temp_path; + const gchar *dest_path; + const gchar *temp_path; gchar *mtime_str; gint width; gint height; @@ -380,15 +374,13 @@ xdg_cache_thumbnail_save_image_data (TumblerThumbnail *thumbnail, temp_file = xdg_cache_cache_get_temp_file (cache_thumbnail->uri, cache_thumbnail->flavor); - /* determine the flavor directory and its path */ + /* determine the flavor directory */ flavor_dir = g_file_get_parent (temp_file); - flavor_dir_path = g_file_get_path (flavor_dir); /* create the flavor directory with user-only read/write/execute permissions */ - g_mkdir_with_parents (flavor_dir_path, S_IRWXU); + g_mkdir_with_parents (g_file_peek_path (flavor_dir), S_IRWXU); - /* free the flavor dir path and GFile */ - g_free (flavor_dir_path); + /* free the flavor dir GFile */ g_object_unref (flavor_dir); /* open a stream to write to (and possibly replace) the temp file */ @@ -411,8 +403,8 @@ xdg_cache_thumbnail_save_image_data (TumblerThumbnail *thumbnail, cache_thumbnail->flavor); /* determine temp and destination paths */ - temp_path = g_file_get_path (temp_file); - dest_path = g_file_get_path (dest_file); + temp_path = g_file_peek_path (temp_file); + dest_path = g_file_peek_path (dest_file); /* try to rename the thumbnail */ if (g_rename (temp_path, dest_path) == -1) @@ -422,10 +414,6 @@ xdg_cache_thumbnail_save_image_data (TumblerThumbnail *thumbnail, g_file_delete (temp_file, NULL, NULL); } - /* free strings */ - g_free (dest_path); - g_free (temp_path); - /* destroy the destination GFile */ g_object_unref (dest_file); } |