[file-roller/wip/jtojnar/clang-analysis: 2/8] archive-libarchive: Use automatic cleanup macros
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller/wip/jtojnar/clang-analysis: 2/8] archive-libarchive: Use automatic cleanup macros
- Date: Tue, 6 Sep 2022 23:41:59 +0000 (UTC)
commit b2318d2283ac2958e94ea9604bbc8091d099d9a6
Author: Jan Tojnar <jtojnar gmail com>
Date: Sat Sep 3 14:18:38 2022 +0200
archive-libarchive: Use automatic cleanup macros
Automatically converted using
https://gitlab.gnome.org/jtojnar/glib-refactoring/-/blob/0a59526c84bd8cc06c5c6e01189ff3b056ef37c8/patches/glib/autocleanup.cocci
and then manually cleaned up the coding style.
src/fr-archive-libarchive.c | 98 +++++++++++----------------------------------
1 file changed, 24 insertions(+), 74 deletions(-)
---
diff --git a/src/fr-archive-libarchive.c b/src/fr-archive-libarchive.c
index ecfa11dd..ac9f0b69 100644
--- a/src/fr-archive-libarchive.c
+++ b/src/fr-archive-libarchive.c
@@ -398,7 +398,7 @@ static goffset
_g_file_get_size (GFile *file,
GCancellable *cancellable)
{
- GFileInfo *info;
+ g_autoptr (GFileInfo) info = NULL;
goffset size;
info = g_file_query_info (file,
@@ -410,7 +410,6 @@ _g_file_get_size (GFile *file,
return 0;
size = g_file_info_get_size (info);
- g_object_unref (info);
return size;
}
@@ -419,7 +418,7 @@ _g_file_get_size (GFile *file,
static GError *
_g_error_new_from_archive_error (const char *s)
{
- char *msg;
+ g_autofree char *msg = NULL;
GError *error;
msg = (s != NULL) ? g_locale_to_utf8 (s, -1, NULL, NULL, NULL) : NULL;
@@ -427,8 +426,6 @@ _g_error_new_from_archive_error (const char *s)
msg = g_strdup ("Fatal error");
error = g_error_new_literal (FR_ERROR, FR_ERROR_COMMAND_ERROR, msg);
- g_free (msg);
-
return error;
}
@@ -710,7 +707,7 @@ _g_file_contains_symlinks_in_path (const char *relative_path,
GHashTable *symlinks)
{
gboolean contains_symlinks = FALSE;
- GFile *parent;
+ g_autoptr (GFile) parent = NULL;
char **components;
int i;
@@ -729,7 +726,6 @@ _g_file_contains_symlinks_in_path (const char *relative_path,
continue;
tmp = g_file_get_child (parent, components[i]);
- g_object_unref (parent);
parent = tmp;
if (g_hash_table_contains (symlinks, parent)) {
@@ -739,7 +735,6 @@ _g_file_contains_symlinks_in_path (const char *relative_path,
}
g_strfreev (components);
- g_object_unref (parent);
return contains_symlinks;
}
@@ -917,17 +912,16 @@ extract_archive_thread (GSimpleAsyncResult *result,
linkname = archive_entry_hardlink (entry);
if (linkname != NULL) {
- char *link_fullpath;
- const char *relative_path;
- GFile *link_file;
- char *oldname;
- char *newname;
+ g_autofree char *link_fullpath = NULL;
+ const char *relative_path;
+ g_autoptr (GFile) link_file = NULL;
+ g_autofree char *oldname = NULL;
+ g_autofree char *newname = NULL;
int r;
link_fullpath = (*linkname == '/') ? g_strdup (linkname) : g_strconcat ("/",
linkname, NULL);
relative_path = _g_path_get_relative_basename_safe (link_fullpath,
extract_data->base_dir, extract_data->junk_paths);
if (relative_path == NULL) {
- g_free (link_fullpath);
archive_read_data_skip (a);
continue;
}
@@ -953,21 +947,10 @@ extract_archive_thread (GSimpleAsyncResult *result,
filetype = AE_IFREG; /* treat as a regular file to save the
data */
}
else {
- char *uri;
- char *msg;
-
- uri = g_file_get_uri (file);
- msg = g_strdup_printf ("Could not create the hard link %s", uri);
+ g_autofree char *uri = g_file_get_uri (file);
+ g_autofree char *msg = g_strdup_printf ("Could not create the hard
link %s", uri);
load_data->error = g_error_new_literal (G_IO_ERROR,
G_IO_ERROR_FAILED, msg);
-
- g_free (msg);
- g_free (uri);
}
-
- g_free (newname);
- g_free (oldname);
- g_object_unref (link_file);
- g_free (link_fullpath);
}
}
@@ -1233,9 +1216,9 @@ save_data_open (struct archive *a,
{
SaveData *save_data = client_data;
LoadData *load_data = LOAD_DATA (save_data);
- GFile *parent;
- char *basename;
- char *tmpname;
+ g_autoptr (GFile) parent = NULL;
+ g_autofree char * basename = NULL;
+ g_autofree char * tmpname = NULL;
if (load_data->error != NULL)
return ARCHIVE_FATAL;
@@ -1246,10 +1229,6 @@ save_data_open (struct archive *a,
save_data->tmp_file = g_file_get_child (parent, tmpname);
save_data->ostream = (GOutputStream *) g_file_create (save_data->tmp_file, G_FILE_CREATE_NONE,
load_data->cancellable, &load_data->error);
- g_free (tmpname);
- g_free (basename);
- g_object_unref (parent);
-
return (save_data->ostream != NULL) ? ARCHIVE_OK : ARCHIVE_FATAL;
}
@@ -1568,7 +1547,7 @@ _archive_write_file (struct archive *b,
GCancellable *cancellable)
{
LoadData *load_data = LOAD_DATA (save_data);
- GFileInfo *info;
+ g_autoptr (GFileInfo) info = NULL;
struct archive_entry *w_entry;
int rb;
@@ -1585,7 +1564,6 @@ _archive_write_file (struct archive *b,
w_entry = archive_entry_new ();
if (! _archive_entry_copy_file_info (w_entry, info, save_data)) {
archive_entry_free (w_entry);
- g_object_unref (info);
return WRITE_ACTION_SKIP_ENTRY;
}
@@ -1593,7 +1571,6 @@ _archive_write_file (struct archive *b,
if (save_data->update && (r_entry != NULL) && (archive_entry_mtime (w_entry) < archive_entry_mtime
(r_entry))) {
archive_entry_free (w_entry);
- g_object_unref (info);
return WRITE_ACTION_WRITE_ENTRY;
}
@@ -1603,7 +1580,7 @@ _archive_write_file (struct archive *b,
/* write the file data */
if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR) {
- GInputStream *istream;
+ g_autoptr (GInputStream) istream = NULL;
istream = (GInputStream *) g_file_read (add_file->file, cancellable, &load_data->error);
if (istream != NULL) {
@@ -1613,8 +1590,6 @@ _archive_write_file (struct archive *b,
archive_write_data (b, save_data->buffer, bytes_read);
fr_archive_progress_inc_completed_bytes (load_data->archive, bytes_read);
}
-
- g_object_unref (istream);
}
}
@@ -1624,7 +1599,6 @@ _archive_write_file (struct archive *b,
load_data->error = g_error_new_literal (FR_ERROR, FR_ERROR_COMMAND_ERROR,
archive_error_string (b));
archive_entry_free (w_entry);
- g_object_unref (info);
return (load_data->error == NULL) ? WRITE_ACTION_SKIP_ENTRY : WRITE_ACTION_ABORT;
}
@@ -1933,18 +1907,12 @@ fr_archive_libarchive_add_files (FrArchive *archive,
for (scan = file_list; scan; scan = scan->next) {
GFile *file = G_FILE (scan->data);
- char *relative_pathname;
- char *archive_pathname;
-
- relative_pathname = g_file_get_relative_path (base_dir, file);
- archive_pathname = g_build_filename (dest_dir, relative_pathname, NULL);
+ g_autofree char *relative_pathname = g_file_get_relative_path (base_dir, file);
+ g_autofree char *archive_pathname = g_build_filename (dest_dir, relative_pathname, NULL);
g_hash_table_insert (add_data->files_to_add,
g_strdup (archive_pathname),
add_file_new (file, archive_pathname));
add_data->n_files_to_add++;
-
- g_free (archive_pathname);
- g_free (relative_pathname);
}
_fr_archive_libarchive_save (archive,
@@ -2142,26 +2110,17 @@ fr_archive_libarchive_rename (FrArchive *archive,
rename_data->n_files_to_rename = 0;
if (is_dir) {
- char *old_dirname;
- char *new_dirname;
- int old_dirname_len;
+ g_autofree char *old_dirname = g_build_filename (current_dir + 1, old_name, "/", NULL);
+ int old_dirname_len = strlen (old_dirname);
+ g_autofree char *new_dirname = g_build_filename (current_dir + 1, new_name, "/", NULL);
GList *scan;
- old_dirname = g_build_filename (current_dir + 1, old_name, "/", NULL);
- old_dirname_len = strlen (old_dirname);
- new_dirname = g_build_filename (current_dir + 1, new_name, "/", NULL);
-
for (scan = file_list; scan; scan = scan->next) {
char *old_pathname = scan->data;
- char *new_pathname;
-
- new_pathname = g_build_filename (new_dirname, old_pathname + old_dirname_len, NULL);
+ char *new_pathname = g_build_filename (new_dirname, old_pathname + old_dirname_len,
NULL);
g_hash_table_insert (rename_data->files_to_rename, g_strdup (old_pathname),
new_pathname);
rename_data->n_files_to_rename++;
}
-
- g_free (new_dirname);
- g_free (old_dirname);
}
else {
char *old_pathname = (char *) file_list->data;
@@ -2277,17 +2236,12 @@ fr_archive_libarchive_add_dropped_files (FrArchive *archive,
for (scan = file_list; scan; scan = scan->next) {
GFile *file = G_FILE (scan->data);
- char *basename;
- char *archive_pathname;
+ g_autofree char *basename = g_file_get_basename (file);
+ g_autofree char *archive_pathname = g_build_filename (dest_dir, basename, NULL);
- basename = g_file_get_basename (file);
- archive_pathname = g_build_filename (dest_dir, basename, NULL);
g_hash_table_insert (add_data->files_to_add,
g_strdup (archive_pathname),
add_file_new (file, archive_pathname));
-
- g_free (archive_pathname);
- g_free (basename);
}
_fr_archive_libarchive_save (archive,
@@ -2336,13 +2290,9 @@ fr_archive_libarchive_update_open_files (FrArchive *archive,
{
GFile *temp_dir = G_FILE (scan_dir->data);
GFile *extracted_file = G_FILE (scan_file->data);
- char *archive_pathname;
-
- archive_pathname = g_file_get_relative_path (temp_dir, extracted_file);
+ g_autofree char *archive_pathname = g_file_get_relative_path (temp_dir, extracted_file);
g_hash_table_insert (add_data->files_to_add, g_strdup (archive_pathname), add_file_new
(extracted_file, archive_pathname));
add_data->n_files_to_add++;
-
- g_free (archive_pathname);
}
_fr_archive_libarchive_save (archive,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]