lib: Port some manual close() cleanups to be glnx_fd_close
Just noticed this while reading some code, we didn't have many manual `out: close()` bits left, this pushes us over the edge to autocleanup almost everywhere. Closes: #332 Approved by: jlebon
This commit is contained in:
1 parent
14ff4f94fb
commit
7847bc7394
5 files changed
+14
-44
No files matched your search
@@ -107,7 +107,7 @@ _ostree_linuxfs_alter_immutable_flag (GFile *path,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
int fd = -1;
|
||||
glnx_fd_close int fd = -1;
|
||||
|
||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||
return FALSE;
|
||||
@@ -129,7 +129,5 @@ _ostree_linuxfs_alter_immutable_flag (GFile *path,
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
if (fd != -1)
|
||||
(void) close (fd);
|
||||
return ret;
|
||||
}
|
||||
@@ -632,7 +632,7 @@ checkout_tree_at (OstreeRepo *self,
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
gboolean did_exist = FALSE;
|
||||
int destination_dfd = -1;
|
||||
glnx_fd_close int destination_dfd = -1;
|
||||
int res;
|
||||
g_autoptr(GVariant) xattrs = NULL;
|
||||
g_autoptr(GFileEnumerator) dir_enum = NULL;
|
||||
@@ -779,8 +779,6 @@ checkout_tree_at (OstreeRepo *self,
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
if (destination_dfd != -1)
|
||||
(void) close (destination_dfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -2558,7 +2558,7 @@ load_metadata_internal (OstreeRepo *self,
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
|
||||
int fd = -1;
|
||||
glnx_fd_close int fd = -1;
|
||||
g_autoptr(GInputStream) ret_stream = NULL;
|
||||
g_autoptr(GVariant) ret_variant = NULL;
|
||||
|
||||
@@ -2586,8 +2586,6 @@ load_metadata_internal (OstreeRepo *self,
|
||||
mfile = g_mapped_file_new_from_fd (fd, FALSE, error);
|
||||
if (!mfile)
|
||||
goto out;
|
||||
(void) close (fd); /* Ignore errors, we have it mapped */
|
||||
fd = -1;
|
||||
ret_variant = g_variant_new_from_data (ostree_metadata_variant_type (objtype),
|
||||
g_mapped_file_get_contents (mfile),
|
||||
g_mapped_file_get_length (mfile),
|
||||
@@ -2632,8 +2630,6 @@ load_metadata_internal (OstreeRepo *self,
|
||||
ot_transfer_out_value (out_variant, &ret_variant);
|
||||
ot_transfer_out_value (out_stream, &ret_stream);
|
||||
out:
|
||||
if (fd != -1)
|
||||
(void) close (fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -172,8 +172,8 @@ copy_dir_recurse (int src_parent_dfd,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
int src_dfd = -1;
|
||||
int dest_dfd = -1;
|
||||
glnx_fd_close int src_dfd = -1;
|
||||
glnx_fd_close int dest_dfd = -1;
|
||||
DIR *srcd = NULL;
|
||||
struct dirent *dent;
|
||||
|
||||
@@ -240,10 +240,6 @@ copy_dir_recurse (int src_parent_dfd,
|
||||
/* Note the srcd owns src_dfd */
|
||||
src_dfd = -1;
|
||||
}
|
||||
if (src_dfd != -1)
|
||||
(void) close (src_dfd);
|
||||
if (dest_dfd != -1)
|
||||
(void) close (dest_dfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -257,8 +253,8 @@ ensure_directory_from_template (int orig_etc_fd,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
int src_dfd = -1;
|
||||
int target_dfd = -1;
|
||||
glnx_fd_close int src_dfd = -1;
|
||||
glnx_fd_close int target_dfd = -1;
|
||||
|
||||
g_assert (path != NULL);
|
||||
g_assert (*path != '/' && *path != '\0');
|
||||
@@ -316,10 +312,6 @@ ensure_directory_from_template (int orig_etc_fd,
|
||||
target_dfd = -1;
|
||||
}
|
||||
out:
|
||||
if (src_dfd != -1)
|
||||
(void) close (src_dfd);
|
||||
if (target_dfd != -1)
|
||||
(void) close (target_dfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -341,7 +333,7 @@ copy_modified_config_file (int orig_etc_fd,
|
||||
gboolean ret = FALSE;
|
||||
struct stat modified_stbuf;
|
||||
struct stat new_stbuf;
|
||||
int dest_parent_dfd = -1;
|
||||
glnx_fd_close int dest_parent_dfd = -1;
|
||||
|
||||
if (fstatat (modified_etc_fd, path, &modified_stbuf, AT_SYMLINK_NOFOLLOW) < 0)
|
||||
{
|
||||
@@ -431,8 +423,6 @@ copy_modified_config_file (int orig_etc_fd,
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
if (dest_parent_dfd != -1)
|
||||
(void) close (dest_parent_dfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -459,9 +449,9 @@ merge_etc_changes (GFile *orig_etc,
|
||||
g_autoptr(GPtrArray) removed = NULL;
|
||||
g_autoptr(GPtrArray) added = NULL;
|
||||
guint i;
|
||||
int orig_etc_fd = -1;
|
||||
int modified_etc_fd = -1;
|
||||
int new_etc_fd = -1;
|
||||
glnx_fd_close int orig_etc_fd = -1;
|
||||
glnx_fd_close int modified_etc_fd = -1;
|
||||
glnx_fd_close int new_etc_fd = -1;
|
||||
|
||||
modified = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_diff_item_unref);
|
||||
removed = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
||||
@@ -538,12 +528,6 @@ merge_etc_changes (GFile *orig_etc,
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
if (orig_etc_fd != -1)
|
||||
(void) close (orig_etc_fd);
|
||||
if (modified_etc_fd != -1)
|
||||
(void) close (modified_etc_fd);
|
||||
if (new_etc_fd != -1)
|
||||
(void) close (new_etc_fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user