[ostree] core: Port libostree to local alloc



commit 8b6bf09d7acf58282e59bfe566bdbb17d2e8700d
Author: Colin Walters <walters verbum org>
Date:   Mon Apr 9 15:45:20 2012 -0400

    core: Port libostree to local alloc

 src/libostree/ostree-core.c         |  104 +++-----
 src/libostree/ostree-mutable-tree.c |   14 +-
 src/libostree/ostree-repo-file.c    |   60 ++---
 src/libostree/ostree-repo.c         |  528 ++++++++++++-----------------------
 src/libostree/ostree-sysroot.c      |    9 +-
 src/libostree/ostree-traverse.c     |   19 +-
 6 files changed, 262 insertions(+), 472 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index f288726..2bea194 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -43,7 +43,7 @@ ostree_validate_rev (const char *rev,
                      GError **error)
 {
   gboolean ret = FALSE;
-  GPtrArray *components = NULL;
+  ot_lptrarray GPtrArray *components = NULL;
 
   if (!ot_util_path_split_validate (rev, &components, error))
     goto out;
@@ -57,7 +57,6 @@ ostree_validate_rev (const char *rev,
 
   ret = TRUE;
  out:
-  g_ptr_array_unref (components);
   return ret;
 }
 
@@ -159,12 +158,12 @@ ostree_get_xattrs_for_file (GFile         *f,
 {
   gboolean ret = FALSE;
   const char *path;
-  GVariant *ret_xattrs = NULL;
+  ssize_t bytes_read;
+  ot_lvariant GVariant *ret_xattrs = NULL;
+  ot_lfree char *xattr_names = NULL;
+  ot_lfree char *xattr_names_canonical = NULL;
   GVariantBuilder builder;
   gboolean builder_initialized = FALSE;
-  char *xattr_names = NULL;
-  char *xattr_names_canonical = NULL;
-  ssize_t bytes_read;
 
   path = ot_gfile_get_path_cached (f);
 
@@ -203,8 +202,6 @@ ostree_get_xattrs_for_file (GFile         *f,
  out:
   if (!builder_initialized)
     g_variant_builder_clear (&builder);
-  g_free (xattr_names);
-  g_free (xattr_names_canonical);
   return ret;
 }
 
@@ -218,12 +215,12 @@ ostree_checksum_file_from_input (GFileInfo        *file_info,
                                  GError          **error)
 {
   gboolean ret = FALSE;
-  GChecksum *ret_checksum = NULL;
-  GVariant *dirmeta = NULL;
-  GVariant *packed = NULL;
   guint8 buf[8192];
   gsize bytes_read;
   guint32 mode;
+  ot_lvariant GVariant *dirmeta = NULL;
+  ot_lvariant GVariant *packed = NULL;
+  GChecksum *ret_checksum = NULL;
 
   if (OSTREE_OBJECT_TYPE_IS_META (objtype))
     return ot_gio_checksum_stream (in, out_checksum, cancellable, error);
@@ -288,8 +285,6 @@ ostree_checksum_file_from_input (GFileInfo        *file_info,
   ot_transfer_out_value (out_checksum, &ret_checksum);
  out:
   ot_clear_checksum (&ret_checksum);
-  ot_clear_gvariant (&dirmeta);
-  ot_clear_gvariant (&packed);
   return ret;
 }
 
@@ -301,10 +296,10 @@ ostree_checksum_file (GFile            *f,
                       GError          **error)
 {
   gboolean ret = FALSE;
-  GFileInfo *file_info = NULL;
+  ot_lobj GFileInfo *file_info = NULL;
+  ot_lobj GInputStream *in = NULL;
+  ot_lvariant GVariant *xattrs = NULL;
   GChecksum *ret_checksum = NULL;
-  GInputStream *in = NULL;
-  GVariant *xattrs = NULL;
 
   if (g_cancellable_set_error_if_cancelled (cancellable, error))
     return FALSE;
@@ -335,10 +330,7 @@ ostree_checksum_file (GFile            *f,
   ret = TRUE;
   ot_transfer_out_value(out_checksum, &ret_checksum);
  out:
-  g_clear_object (&file_info);
-  g_clear_object (&in);
   ot_clear_checksum(&ret_checksum);
-  ot_clear_gvariant(&xattrs);
   return ret;
 }
 
@@ -480,8 +472,8 @@ ostree_unwrap_metadata (GVariant              *container,
                         GError               **error)
 {
   gboolean ret = FALSE;
-  GVariant *ret_variant = NULL;
   guint32 actual_type;
+  ot_lvariant GVariant *ret_variant = NULL;
 
   g_variant_get (container, "(uv)",
                  &actual_type, &ret_variant);
@@ -497,7 +489,6 @@ ostree_unwrap_metadata (GVariant              *container,
   ret = TRUE;
   ot_transfer_out_value (out_variant, &ret_variant);
  out:
-  ot_clear_gvariant (&ret_variant);
   return ret;
 }
 
@@ -508,8 +499,8 @@ ostree_map_metadata_file (GFile                       *file,
                           GError                     **error)
 {
   gboolean ret = FALSE;
-  GVariant *ret_variant = NULL;
-  GVariant *container = NULL;
+  ot_lvariant GVariant *ret_variant = NULL;
+  ot_lvariant GVariant *container = NULL;
 
   if (!ot_util_variant_map (file, OSTREE_SERIALIZED_VARIANT_FORMAT,
                             &container, error))
@@ -526,8 +517,6 @@ ostree_map_metadata_file (GFile                       *file,
   ret = TRUE;
   ot_transfer_out_value(out_variant, &ret_variant);
  out:
-  ot_clear_gvariant (&ret_variant);
-  ot_clear_gvariant (&container);
   return ret;
 }
 
@@ -786,10 +775,10 @@ ostree_parse_archived_file_meta (GVariant         *metadata,
                                  GError          **error)
 {
   gboolean ret = FALSE;
-  GFileInfo *ret_file_info = NULL;
-  GVariant *ret_xattrs = NULL;
   guint32 version, uid, gid, mode, rdev;
   const char *symlink_target;
+  ot_lobj GFileInfo *ret_file_info = NULL;
+  ot_lvariant GVariant *ret_xattrs = NULL;
 
   g_variant_get (metadata, "(uuuuu&s a(ayay))",
                  &version, &uid, &gid, &mode, &rdev,
@@ -842,8 +831,6 @@ ostree_parse_archived_file_meta (GVariant         *metadata,
   ot_transfer_out_value(out_file_info, &ret_file_info);
   ot_transfer_out_value(out_xattrs, &ret_xattrs);
  out:
-  g_clear_object (&ret_file_info);
-  ot_clear_gvariant (&ret_xattrs);
   return ret;
 }
 
@@ -857,13 +844,13 @@ ostree_create_file_from_input (GFile            *dest_file,
                                GCancellable     *cancellable,
                                GError          **error)
 {
-  const char *dest_path;
   gboolean ret = FALSE;
-  GFileOutputStream *out = NULL;
+  const char *dest_path;
   guint32 uid, gid, mode;
-  GChecksum *ret_checksum = NULL;
   gboolean is_meta;
   gboolean is_archived_content;
+  ot_lobj GFileOutputStream *out = NULL;
+  GChecksum *ret_checksum = NULL;
 
   is_meta = OSTREE_OBJECT_TYPE_IS_META (objtype);
   is_archived_content = objtype == OSTREE_OBJECT_TYPE_ARCHIVED_FILE_CONTENT;
@@ -1008,7 +995,6 @@ ostree_create_file_from_input (GFile            *dest_file,
       (void) unlink (dest_path);
     }
   ot_clear_checksum (&ret_checksum);
-  g_clear_object (&out);
   return ret;
 }
 
@@ -1066,12 +1052,12 @@ ostree_create_temp_file_from_input (GFile            *dir,
                                     GError          **error)
 {
   gboolean ret = FALSE;
-  GChecksum *ret_checksum = NULL;
-  GString *tmp_name = NULL;
-  char *possible_name = NULL;
-  GFile *possible_file = NULL;
   GError *temp_error = NULL;
   int i = 0;
+  ot_lfree char *possible_name = NULL;
+  ot_lobj GFile *possible_file = NULL;
+  GChecksum *ret_checksum = NULL;
+  GString *tmp_name = NULL;
 
   tmp_name = create_tmp_string (ot_gfile_get_path_cached (dir),
                                 prefix, suffix);
@@ -1121,8 +1107,6 @@ ostree_create_temp_file_from_input (GFile            *dir,
  out:
   if (tmp_name)
     g_string_free (tmp_name, TRUE);
-  g_free (possible_name);
-  g_clear_object (&possible_file);
   ot_clear_checksum (&ret_checksum);
   return ret;
 }
@@ -1137,8 +1121,8 @@ ostree_create_temp_regular_file (GFile            *dir,
                                  GError          **error)
 {
   gboolean ret = FALSE;
-  GFile *ret_file = NULL;
-  GOutputStream *ret_stream = NULL;
+  ot_lobj GFile *ret_file = NULL;
+  ot_lobj GOutputStream *ret_stream = NULL;
 
   if (!ostree_create_temp_file_from_input (dir, prefix, suffix, NULL, NULL, NULL,
                                            OSTREE_OBJECT_TYPE_RAW_FILE, &ret_file,
@@ -1153,8 +1137,6 @@ ostree_create_temp_regular_file (GFile            *dir,
   ot_transfer_out_value(out_file, &ret_file);
   ot_transfer_out_value(out_stream, &ret_stream);
  out:
-  g_clear_object (&ret_file);
-  g_clear_object (&ret_stream);
   return ret;
 }
 
@@ -1168,10 +1150,10 @@ ostree_create_temp_hardlink (GFile            *dir,
                              GError          **error)
 {
   gboolean ret = FALSE;
-  GString *tmp_name = NULL;
-  char *possible_name = NULL;
-  GFile *possible_file = NULL;
   int i = 0;
+  ot_lfree char *possible_name = NULL;
+  ot_lobj GFile *possible_file = NULL;
+  GString *tmp_name = NULL;
 
   tmp_name = create_tmp_string (ot_gfile_get_path_cached (dir),
                                 prefix, suffix);
@@ -1214,8 +1196,6 @@ ostree_create_temp_hardlink (GFile            *dir,
  out:
   if (tmp_name)
     g_string_free (tmp_name, TRUE);
-  g_free (possible_name);
-  g_clear_object (&possible_file);
   return ret;
 }
 
@@ -1229,10 +1209,10 @@ ostree_read_pack_entry_raw (guchar        *pack_data,
                             GError       **error)
 {
   gboolean ret = FALSE;
-  GVariant *ret_entry = NULL;
   guint64 entry_start;
   guint64 entry_end;
   guint32 entry_len;
+  ot_lvariant GVariant *ret_entry = NULL;
 
   if (G_UNLIKELY (!(offset <= pack_len)))
     {
@@ -1277,7 +1257,6 @@ ostree_read_pack_entry_raw (guchar        *pack_data,
   ret = TRUE;
   ot_transfer_out_value (out_entry, &ret_entry);
  out:
-  ot_clear_gvariant (&ret_entry);
   return ret;
 }
 
@@ -1330,10 +1309,10 @@ ostree_read_pack_entry_variant (GVariant            *pack_entry,
                                 GError             **error)
 {
   gboolean ret = FALSE;
-  GInputStream *stream = NULL;
-  GVariant *container_variant = NULL;
-  GVariant *ret_variant = NULL;
   guint32 actual_type;
+  ot_lobj GInputStream *stream = NULL;
+  ot_lvariant GVariant *container_variant = NULL;
+  ot_lvariant GVariant *ret_variant = NULL;
 
   stream = ostree_read_pack_entry_as_stream (pack_entry);
   
@@ -1356,9 +1335,6 @@ ostree_read_pack_entry_variant (GVariant            *pack_entry,
   ret = TRUE;
   ot_transfer_out_value (out_variant, &ret_variant);
  out:
-  g_clear_object (&stream);
-  ot_clear_gvariant (&ret_variant);
-  ot_clear_gvariant (&container_variant);
   return ret;
 }
 
@@ -1369,10 +1345,10 @@ ostree_pack_index_search (GVariant   *index,
                           guint64    *out_offset)
 {
   gboolean ret = FALSE;
-  GVariant *index_contents;
   gsize imax, imin;
   gsize n;
   guint32 target_objtype;
+  ot_lvariant GVariant *index_contents = NULL;
 
   index_contents = g_variant_get_child_value (index, 2);
 
@@ -1427,7 +1403,6 @@ ostree_pack_index_search (GVariant   *index,
     }
 
  out:
-  ot_clear_gvariant (&index_contents);
   return ret;
 }
 
@@ -1550,10 +1525,10 @@ ostree_validate_structureof_dirtree (GVariant      *dirtree,
                                      GError       **error)
 {
   gboolean ret = FALSE;
-  GVariantIter *contents_iter = NULL;
   const char *filename;
   const char *meta_checksum;
   const char *content_checksum;
+  GVariantIter *contents_iter = NULL;
 
   if (!validate_variant (dirtree, OSTREE_TREE_GVARIANT_FORMAT, error))
     goto out;
@@ -1668,10 +1643,10 @@ ostree_validate_structureof_pack_index (GVariant      *index,
 {
   gboolean ret = FALSE;
   const char *header;
-  GVariantIter *content_iter = NULL;
   guint32 objtype;
-  GVariant *csum_bytes = NULL;
   guint64 offset;
+  ot_lvariant GVariant *csum_bytes = NULL;
+  GVariantIter *content_iter = NULL;
 
   if (!validate_variant (index, OSTREE_PACK_INDEX_VARIANT_FORMAT, error))
     goto out;
@@ -1701,7 +1676,6 @@ ostree_validate_structureof_pack_index (GVariant      *index,
  out:
   if (content_iter)
     g_variant_iter_free (content_iter);
-  ot_clear_gvariant (&csum_bytes);
   return ret;
 }
 
@@ -1711,8 +1685,8 @@ ostree_validate_structureof_pack_superindex (GVariant      *superindex,
 {
   gboolean ret = FALSE;
   const char *header;
-  GVariant *csum_bytes = NULL;
-  GVariant *bloom = NULL;
+  ot_lvariant GVariant *csum_bytes = NULL;
+  ot_lvariant GVariant *bloom = NULL;
   GVariantIter *content_iter = NULL;
 
   if (!validate_variant (superindex, OSTREE_PACK_SUPER_INDEX_VARIANT_FORMAT, error))
@@ -1741,7 +1715,5 @@ ostree_validate_structureof_pack_superindex (GVariant      *superindex,
  out:
   if (content_iter)
     g_variant_iter_free (content_iter);
-  ot_clear_gvariant (&csum_bytes);
-  ot_clear_gvariant (&bloom);
   return ret;
 }
diff --git a/src/libostree/ostree-mutable-tree.c b/src/libostree/ostree-mutable-tree.c
index 37acc80..890e1e7 100644
--- a/src/libostree/ostree-mutable-tree.c
+++ b/src/libostree/ostree-mutable-tree.c
@@ -166,7 +166,7 @@ ostree_mutable_tree_ensure_dir (OstreeMutableTree *self,
                                 GError           **error)
 {
   gboolean ret = FALSE;
-  OstreeMutableTree *ret_dir = NULL;
+  ot_lobj OstreeMutableTree *ret_dir = NULL;
 
   g_return_val_if_fail (name != NULL, FALSE);
 
@@ -188,7 +188,6 @@ ostree_mutable_tree_ensure_dir (OstreeMutableTree *self,
   ret = TRUE;
   ot_transfer_out_value (out_subdir, &ret_dir);
  out:
-  g_clear_object (&ret_dir);
   return ret;
 }
 
@@ -200,8 +199,8 @@ ostree_mutable_tree_lookup (OstreeMutableTree   *self,
                             GError             **error)
 {
   gboolean ret = FALSE;
-  OstreeMutableTree *ret_subdir = NULL;
-  char *ret_file_checksum = NULL;
+  ot_lobj OstreeMutableTree *ret_subdir = NULL;
+  ot_lfree char *ret_file_checksum = NULL;
   
   ret_subdir = ot_gobject_refz (g_hash_table_lookup (self->subdirs, name));
   if (!ret_subdir)
@@ -218,8 +217,6 @@ ostree_mutable_tree_lookup (OstreeMutableTree   *self,
   ot_transfer_out_value (out_file_checksum, &ret_file_checksum);
   ot_transfer_out_value (out_subdir, &ret_subdir);
  out:
-  g_free (ret_file_checksum);
-  g_clear_object (&ret_subdir);
   return ret;
 }
 
@@ -232,8 +229,8 @@ ostree_mutable_tree_ensure_parent_dirs (OstreeMutableTree  *self,
 {
   gboolean ret = FALSE;
   int i;
-  OstreeMutableTree *ret_parent = NULL;
-  OstreeMutableTree *subdir = self;
+  OstreeMutableTree *subdir = self; /* nofree */
+  ot_lobj OstreeMutableTree *ret_parent = NULL;
 
   g_assert (metadata_checksum != NULL);
 
@@ -268,7 +265,6 @@ ostree_mutable_tree_ensure_parent_dirs (OstreeMutableTree  *self,
   ret = TRUE;
   ot_transfer_out_value (out_parent, &ret_parent);
  out:
-  g_clear_object (&ret_parent);
   return ret;
 }
 
diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c
index d81adbe..53d3bc2 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -146,11 +146,11 @@ do_resolve_commit (OstreeRepoFile  *self,
                    GError         **error)
 {
   gboolean ret = FALSE;
-  GVariant *commit = NULL;
-  GVariant *root_contents = NULL;
-  GVariant *root_metadata = NULL;
   const char *tree_contents_checksum;
   const char *tree_meta_checksum;
+  ot_lvariant GVariant *commit = NULL;
+  ot_lvariant GVariant *root_contents = NULL;
+  ot_lvariant GVariant *root_metadata = NULL;
 
   g_assert (self->parent == NULL);
 
@@ -181,9 +181,6 @@ do_resolve_commit (OstreeRepoFile  *self,
 
   ret = TRUE;
  out:
-  ot_clear_gvariant (&commit);
-  ot_clear_gvariant (&root_metadata);
-  ot_clear_gvariant (&root_contents);
   return ret;
 }
 
@@ -192,11 +189,11 @@ do_resolve_nonroot (OstreeRepoFile     *self,
                     GError            **error)
 {
   gboolean ret = FALSE;
-  GVariant *container = NULL;
-  GVariant *tree_contents = NULL;
-  GVariant *tree_metadata = NULL;
   gboolean is_dir;
   int i;
+  ot_lvariant GVariant *container = NULL;
+  ot_lvariant GVariant *tree_contents = NULL;
+  ot_lvariant GVariant *tree_metadata = NULL;
 
   i = ostree_repo_file_tree_find_child (self->parent, self->name, &is_dir, &container);
   
@@ -245,9 +242,6 @@ do_resolve_nonroot (OstreeRepoFile     *self,
 
   ret = TRUE;
  out:
-  ot_clear_gvariant (&container);
-  ot_clear_gvariant (&tree_metadata);
-  ot_clear_gvariant (&tree_contents);
   return ret;
 }
 
@@ -294,9 +288,9 @@ ostree_repo_file_get_xattrs (OstreeRepoFile  *self,
                               GError         **error)
 {
   gboolean ret = FALSE;
-  GVariant *ret_xattrs = NULL;
-  GVariant *metadata = NULL;
-  GFile *local_file = NULL;
+  ot_lvariant GVariant *ret_xattrs = NULL;
+  ot_lvariant GVariant *metadata = NULL;
+  ot_lobj GFile *local_file = NULL;
 
   if (!ostree_repo_file_ensure_resolved (self, error))
     goto out;
@@ -324,9 +318,6 @@ ostree_repo_file_get_xattrs (OstreeRepoFile  *self,
   ret = TRUE;
   ot_transfer_out_value(out_xattrs, &ret_xattrs);
  out:
-  ot_clear_gvariant (&ret_xattrs);
-  ot_clear_gvariant (&metadata);
-  g_clear_object (&local_file);
   return ret;
 }
 
@@ -698,8 +689,8 @@ query_child_info_dir (OstreeRepo               *repo,
                       GError                  **error)
 {
   gboolean ret = FALSE;
-  GFileInfo *ret_info = NULL;
-  GVariant *metadata = NULL;
+  ot_lobj GFileInfo *ret_info = NULL;
+  ot_lvariant GVariant *metadata = NULL;
 
   ret_info = g_file_info_new ();
 
@@ -822,14 +813,14 @@ ostree_repo_file_tree_query_child (OstreeRepoFile  *self,
                                     GCancellable    *cancellable,
                                     GError         **error)
 {
-  const char *name = NULL;
   gboolean ret = FALSE;
-  GFileInfo *ret_info = NULL;
-  GVariant *files_variant = NULL;
-  GVariant *dirs_variant = NULL;
-  GVariant *tree_child_metadata = NULL;
-  GFileAttributeMatcher *matcher = NULL;
+  const char *name = NULL;
   int c;
+  ot_lobj GFileInfo *ret_info = NULL;
+  ot_lvariant GVariant *files_variant = NULL;
+  ot_lvariant GVariant *dirs_variant = NULL;
+  ot_lvariant GVariant *tree_child_metadata = NULL;
+  GFileAttributeMatcher *matcher = NULL;
 
   if (!ostree_repo_file_ensure_resolved (self, error))
     goto out;
@@ -890,12 +881,8 @@ ostree_repo_file_tree_query_child (OstreeRepoFile  *self,
   ret = TRUE;
   ot_transfer_out_value(out_info, &ret_info);
  out:
-  g_clear_object (&ret_info);
   if (matcher)
     g_file_attribute_matcher_unref (matcher);
-  ot_clear_gvariant (&tree_child_metadata);
-  ot_clear_gvariant (&files_variant);
-  ot_clear_gvariant (&dirs_variant);
   return ret;
 }
 
@@ -906,9 +893,9 @@ ostree_repo_file_query_info (GFile                *file,
 			     GCancellable         *cancellable,
 			     GError              **error)
 {
-  OstreeRepoFile *self = OSTREE_REPO_FILE (file);
   gboolean ret = FALSE;
-  GFileInfo *info = NULL;
+  OstreeRepoFile *self = OSTREE_REPO_FILE (file);
+  ot_lobj GFileInfo *info = NULL;
 
   if (!ostree_repo_file_ensure_resolved (self, error))
     goto out;
@@ -931,6 +918,8 @@ ostree_repo_file_query_info (GFile                *file,
  out:
   if (!ret)
     g_clear_object (&info);
+  else
+    g_object_ref (info);
   return info;
 }
 
@@ -956,10 +945,10 @@ ostree_repo_file_read (GFile         *file,
 		       GError       **error)
 {
   gboolean ret = FALSE;
-  GFile *local_file = NULL;
-  GFileInputStream *ret_stream = NULL;
   OstreeRepoFile *self = OSTREE_REPO_FILE (file);
   const char *checksum;
+  ot_lobj GFile *local_file = NULL;
+  ot_lobj GFileInputStream *ret_stream = NULL;
 
   if (!ostree_repo_file_ensure_resolved (self, error))
     goto out;
@@ -990,9 +979,10 @@ ostree_repo_file_read (GFile         *file,
   
   ret = TRUE;
  out:
-  g_clear_object (&local_file);
   if (!ret)
     g_clear_object (&ret_stream);
+  else
+    g_object_ref (ret_stream);
   return ret_stream;
 }
 
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 84b8a23..ff4c46a 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -219,10 +219,10 @@ parse_rev_file (OstreeRepo     *self,
                 char          **sha256,
                 GError        **error)
 {
+  gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
   GError *temp_error = NULL;
-  gboolean ret = FALSE;
-  char *rev = NULL;
+  ot_lfree char *rev = NULL;
 
   if (!ot_gfile_load_contents_utf8 (f, &rev, NULL, NULL, &temp_error))
     goto out;
@@ -272,7 +272,6 @@ parse_rev_file (OstreeRepo     *self,
   ot_transfer_out_value(sha256, &rev);
   ret = TRUE;
  out:
-  g_free (rev);
   return ret;
 }
 
@@ -285,10 +284,10 @@ find_rev_in_remotes (OstreeRepo         *self,
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
   GError *temp_error = NULL;
-  GFileEnumerator *dir_enum = NULL;
-  GFileInfo *file_info = NULL;
-  GFile *child = NULL;
-  GFile *ret_file = NULL;
+  ot_lobj GFileEnumerator *dir_enum = NULL;
+  ot_lobj GFileInfo *file_info = NULL;
+  ot_lobj GFile *child = NULL;
+  ot_lobj GFile *ret_file = NULL;
 
   dir_enum = g_file_enumerate_children (priv->remote_heads_dir, OSTREE_GIO_FAST_QUERYINFO,
                                         G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -323,10 +322,6 @@ find_rev_in_remotes (OstreeRepo         *self,
   ret = TRUE;
   ot_transfer_out_value (out_file, &ret_file);
  out:
-  g_clear_object (&child);
-  g_clear_object (&ret_file);
-  g_clear_object (&dir_enum);
-  g_clear_object (&file_info);
   return ret;
 }
 
@@ -337,15 +332,15 @@ ostree_repo_resolve_rev (OstreeRepo     *self,
                          char          **sha256,
                          GError        **error)
 {
-  OstreeRepoPrivate *priv = GET_PRIVATE (self);
   gboolean ret = FALSE;
-  char *tmp = NULL;
-  char *tmp2 = NULL;
-  char *ret_rev = NULL;
-  GFile *child = NULL;
-  GFile *origindir = NULL;
+  OstreeRepoPrivate *priv = GET_PRIVATE (self);
   GError *temp_error = NULL;
-  GVariant *commit = NULL;
+  ot_lfree char *tmp = NULL;
+  ot_lfree char *tmp2 = NULL;
+  ot_lfree char *ret_rev = NULL;
+  ot_lobj GFile *child = NULL;
+  ot_lobj GFile *origindir = NULL;
+  ot_lvariant GVariant *commit = NULL;
   
   g_return_val_if_fail (rev != NULL, FALSE);
 
@@ -426,12 +421,6 @@ ostree_repo_resolve_rev (OstreeRepo     *self,
   ot_transfer_out_value(sha256, &ret_rev);
   ret = TRUE;
  out:
-  ot_clear_gvariant (&commit);
-  g_free (tmp);
-  g_free (tmp2);
-  g_clear_object (&child);
-  g_clear_object (&origindir);
-  g_free (ret_rev);
   return ret;
 }
 
@@ -442,12 +431,12 @@ write_checksum_file (GFile *parentdir,
                      GError **error)
 {
   gboolean ret = FALSE;
-  GFile *parent = NULL;
-  GFile *child = NULL;
-  GOutputStream *out = NULL;
   gsize bytes_written;
-  GPtrArray *components = NULL;
   int i;
+  ot_lobj GFile *parent = NULL;
+  ot_lobj GFile *child = NULL;
+  ot_lobj GOutputStream *out = NULL;
+  ot_lptrarray GPtrArray *components = NULL;
 
   if (!ostree_validate_checksum_string (sha256, error))
     goto out;
@@ -494,9 +483,6 @@ write_checksum_file (GFile *parentdir,
 
   ret = TRUE;
  out:
-  g_clear_object (&parent);
-  g_clear_object (&child);
-  g_clear_object (&out);
   return ret;
 }
 
@@ -555,10 +541,10 @@ ostree_repo_write_config (OstreeRepo *self,
                           GKeyFile   *new_config,
                           GError    **error)
 {
+  gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  char *data = NULL;
+  ot_lfree char *data = NULL;
   gsize len;
-  gboolean ret = FALSE;
 
   g_return_val_if_fail (priv->inited, FALSE);
 
@@ -574,7 +560,6 @@ ostree_repo_write_config (OstreeRepo *self,
 
   ret = TRUE;
  out:
-  g_free (data);
   return ret;
 }
 
@@ -621,7 +606,7 @@ keyfile_get_value_with_default (GKeyFile      *keyfile,
 {
   gboolean ret = FALSE;
   GError *temp_error = NULL;
-  char *ret_value;
+  ot_lfree char *ret_value;
 
   ret_value = g_key_file_get_value (keyfile, section, value, &temp_error);
   if (temp_error)
@@ -641,18 +626,17 @@ keyfile_get_value_with_default (GKeyFile      *keyfile,
   ret = TRUE;
   ot_transfer_out_value(out_value, &ret_value);
  out:
-  g_free (ret_value);
   return ret;
 }
                                 
 gboolean
 ostree_repo_check (OstreeRepo *self, GError **error)
 {
-  OstreeRepoPrivate *priv = GET_PRIVATE (self);
   gboolean ret = FALSE;
-  char *version = NULL;;
-  char *mode = NULL;;
+  OstreeRepoPrivate *priv = GET_PRIVATE (self);
   gboolean is_archive;
+  ot_lfree char *version = NULL;;
+  ot_lfree char *mode = NULL;;
 
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
@@ -716,8 +700,6 @@ ostree_repo_check (OstreeRepo *self, GError **error)
   
   ret = TRUE;
  out:
-  g_free (mode);
-  g_free (version);
   return ret;
 }
 
@@ -794,8 +776,8 @@ commit_tmpfile_trusted (OstreeRepo        *self,
                         GError           **error)
 {
   gboolean ret = FALSE;
-  GFile *dest_file = NULL;
-  GFile *checksum_dir = NULL;
+  ot_lobj GFile *dest_file = NULL;
+  ot_lobj GFile *checksum_dir = NULL;
 
   dest_file = ostree_repo_get_object_path (self, checksum, objtype);
   checksum_dir = g_file_get_parent (dest_file);
@@ -818,8 +800,6 @@ commit_tmpfile_trusted (OstreeRepo        *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&dest_file);
-  g_clear_object (&checksum_dir);
   return ret;
 }
 
@@ -835,14 +815,14 @@ impl_stage_archive_file_object_from_raw (OstreeRepo         *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GChecksum *ret_checksum = NULL;
-  GVariant *archive_metadata = NULL;
-  GFileInfo *temp_info = NULL;
-  GFile *meta_temp_file = NULL;
-  GFile *content_temp_file = NULL;
-  GVariant *serialized = NULL;
-  GInputStream *mem = NULL;
   const char *actual_checksum;
+  ot_lvariant GVariant *archive_metadata = NULL;
+  ot_lobj GFileInfo *temp_info = NULL;
+  ot_lobj GFile *meta_temp_file = NULL;
+  ot_lobj GFile *content_temp_file = NULL;
+  ot_lobj GInputStream *mem = NULL;
+  ot_lvariant GVariant *serialized = NULL;
+  GChecksum *ret_checksum = NULL;
   
   archive_metadata = ostree_create_archive_file_metadata (file_info, xattrs);
   
@@ -910,12 +890,6 @@ impl_stage_archive_file_object_from_raw (OstreeRepo         *self,
   ret = TRUE;
   ot_transfer_out_value (out_checksum, &ret_checksum);
  out:
-  ot_clear_gvariant (&serialized);
-  ot_clear_gvariant (&archive_metadata);
-  g_clear_object (&mem);
-  g_clear_object (&temp_info);
-  g_clear_object (&meta_temp_file);
-  g_clear_object (&content_temp_file);
   ot_clear_checksum (&ret_checksum);
   return ret;
 }
@@ -934,13 +908,13 @@ stage_object_impl (OstreeRepo         *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GChecksum *ret_checksum = NULL;
-  GFileInfo *temp_info = NULL;
-  GFile *temp_file = NULL;
-  GFile *stored_path = NULL;
-  char *pack_checksum = NULL;
   guint64 pack_offset;
   const char *actual_checksum;
+  ot_lobj GFileInfo *temp_info = NULL;
+  ot_lobj GFile *temp_file = NULL;
+  ot_lobj GFile *stored_path = NULL;
+  ot_lfree char *pack_checksum = NULL;
+  GChecksum *ret_checksum = NULL;
 
   g_return_val_if_fail (priv->in_transaction, FALSE);
   
@@ -1035,10 +1009,6 @@ stage_object_impl (OstreeRepo         *self,
  out:
   if (temp_file)
     (void) unlink (ot_gfile_get_path_cached (temp_file));
-  g_clear_object (&temp_file);
-  g_clear_object (&temp_info);
-  g_clear_object (&stored_path);
-  g_free (pack_checksum);
   ot_clear_checksum (&ret_checksum);
   return ret;
 }
@@ -1100,9 +1070,9 @@ stage_gvariant_object (OstreeRepo         *self,
                        GError            **error)
 {
   gboolean ret = FALSE;
+  ot_lvariant GVariant *serialized = NULL;
+  ot_lobj GInputStream *mem = NULL;
   GChecksum *ret_checksum = NULL;
-  GVariant *serialized = NULL;
-  GInputStream *mem = NULL;
 
   serialized = ostree_wrap_metadata_variant (type, variant);
   mem = g_memory_input_stream_new_from_data (g_variant_get_data (serialized),
@@ -1117,9 +1087,7 @@ stage_gvariant_object (OstreeRepo         *self,
   ret = TRUE;
   ot_transfer_out_value(out_checksum, &ret_checksum);
  out:
-  g_clear_object (&mem);
   ot_clear_checksum (&ret_checksum);
-  ot_clear_gvariant (&serialized)
   return ret;
 }
 
@@ -1132,8 +1100,8 @@ stage_directory_meta (OstreeRepo   *self,
                       GError      **error)
 {
   gboolean ret = FALSE;
+  ot_lvariant GVariant *dirmeta = NULL;
   GChecksum *ret_checksum = NULL;
-  GVariant *dirmeta = NULL;
 
   if (g_cancellable_set_error_if_cancelled (cancellable, error))
     return FALSE;
@@ -1148,7 +1116,6 @@ stage_directory_meta (OstreeRepo   *self,
   ot_transfer_out_value(out_checksum, &ret_checksum);
  out:
   ot_clear_checksum (&ret_checksum);
-  ot_clear_gvariant (&dirmeta);
   return ret;
 }
 
@@ -1225,10 +1192,10 @@ enumerate_refs_recurse (OstreeRepo    *repo,
                         GError       **error)
 {
   gboolean ret = FALSE;
-  GFileInfo *file_info = NULL;
-  GFileEnumerator *enumerator = NULL;
-  GFile *child = NULL;
   GError *temp_error = NULL;
+  ot_lobj GFileInfo *file_info = NULL;
+  ot_lobj GFileEnumerator *enumerator = NULL;
+  ot_lobj GFile *child = NULL;
 
   enumerator = g_file_enumerate_children (dir, OSTREE_GIO_FAST_QUERYINFO,
                                           G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -1268,8 +1235,6 @@ enumerate_refs_recurse (OstreeRepo    *repo,
 
   ret = TRUE;
  out:
-  g_clear_object (&file_info);
-  g_clear_object (&child);
   return ret;
 }
 
@@ -1280,8 +1245,8 @@ ostree_repo_list_all_refs (OstreeRepo       *repo,
                            GError          **error)
 {
   gboolean ret = FALSE;
-  GHashTable *ret_all_refs = NULL;
-  GFile *heads_dir = NULL;
+  ot_lhash GHashTable *ret_all_refs = NULL;
+  ot_lobj GFile *heads_dir = NULL;
 
   ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
@@ -1292,7 +1257,6 @@ ostree_repo_list_all_refs (OstreeRepo       *repo,
   ret = TRUE;
   ot_transfer_out_value (out_all_refs, &ret_all_refs);
  out:
-  g_clear_object (&heads_dir);
   return ret;
 }
 
@@ -1302,13 +1266,13 @@ write_ref_summary (OstreeRepo      *self,
                    GError         **error)
 {
   gboolean ret = FALSE;
-  GHashTable *all_refs = NULL;
   GHashTableIter hash_iter;
   gpointer key, value;
-  GFile *summary_path = NULL;
-  GOutputStream *out = NULL;
   gsize bytes_written;
-  char *buf = NULL;
+  ot_lhash GHashTable *all_refs = NULL;
+  ot_lobj GFile *summary_path = NULL;
+  ot_lobj GOutputStream *out = NULL;
+  ot_lfree char *buf = NULL;
 
   if (!ostree_repo_list_all_refs (self, &all_refs, cancellable, error))
     goto out;
@@ -1337,10 +1301,6 @@ write_ref_summary (OstreeRepo      *self,
 
   ret = TRUE;
  out:
-  g_free (buf);
-  g_clear_object (&summary_path);
-  g_clear_object (&out);
-  g_hash_table_unref (all_refs);
   return ret;
 }
 
@@ -1353,7 +1313,7 @@ ostree_repo_write_ref (OstreeRepo  *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GFile *dir = NULL;
+  ot_lobj GFile *dir = NULL;
 
   if (remote == NULL)
     dir = g_object_ref (priv->local_heads_dir);
@@ -1376,7 +1336,6 @@ ostree_repo_write_ref (OstreeRepo  *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&dir);
   return ret;
 }
 
@@ -1394,9 +1353,9 @@ ostree_repo_stage_commit (OstreeRepo *self,
                           GError      **error)
 {
   gboolean ret = FALSE;
+  ot_lfree char *ret_commit = NULL;
+  ot_lvariant GVariant *commit = NULL;
   GChecksum *ret_commit_obj = NULL;
-  char *ret_commit = NULL;
-  GVariant *commit = NULL;
   GDateTime *now = NULL;
 
   g_return_val_if_fail (branch != NULL, FALSE);
@@ -1423,9 +1382,7 @@ ostree_repo_stage_commit (OstreeRepo *self,
   ret = TRUE;
   ot_transfer_out_value(out_commit, &ret_commit);
  out:
-  g_free (ret_commit);
   ot_clear_checksum (&ret_commit_obj);
-  ot_clear_gvariant (&commit);
   if (now)
     g_date_time_unref (now);
   return ret;
@@ -1441,9 +1398,9 @@ list_files_in_dir_matching (GFile                  *dir,
 {
   gboolean ret = FALSE;
   GError *temp_error = NULL;
-  GFileEnumerator *enumerator = NULL;
-  GFileInfo *file_info = NULL;
-  GPtrArray *ret_files = NULL;
+  ot_lobj GFileEnumerator *enumerator = NULL;
+  ot_lobj GFileInfo *file_info = NULL;
+  ot_lptrarray GPtrArray *ret_files = NULL;
 
   g_return_val_if_fail (prefix != NULL || suffix != NULL, FALSE);
 
@@ -1494,10 +1451,6 @@ list_files_in_dir_matching (GFile                  *dir,
   ret = TRUE;
   ot_transfer_out_value (out_files, &ret_files);
  out:
-  if (ret_files)
-    g_ptr_array_unref (ret_files);
-  g_clear_object (&file_info);
-  g_clear_object (&enumerator);
   return ret;
 }
 
@@ -1510,8 +1463,8 @@ map_variant_file_check_header_string (GFile         *path,
                                       GError       **error)
 {
   gboolean ret = FALSE;
-  GVariant *ret_variant = NULL;
   const char *header;
+  ot_lvariant GVariant *ret_variant = NULL;
 
   if (!ot_util_variant_map (path, variant_type, &ret_variant, error))
     goto out;
@@ -1530,7 +1483,6 @@ map_variant_file_check_header_string (GFile         *path,
   ret = TRUE;
   ot_transfer_out_value (out_variant, &ret_variant);
  out:
-  ot_clear_gvariant (&ret_variant);
   return ret;
 }
 
@@ -1558,10 +1510,10 @@ list_pack_indexes_from_dir (OstreeRepo              *self,
                             GError                 **error)
 {
   gboolean ret = FALSE;
-  GPtrArray *index_files = NULL;
-  GPtrArray *ret_indexes = NULL;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
   guint i;
+  ot_lptrarray GPtrArray *index_files = NULL;
+  ot_lptrarray GPtrArray *ret_indexes = NULL;
 
   if (!list_files_in_dir_matching (priv->pack_dir,
                                    "ostpack-", ".index",
@@ -1580,10 +1532,6 @@ list_pack_indexes_from_dir (OstreeRepo              *self,
   ret = TRUE;
   ot_transfer_out_value (out_indexes, &ret_indexes);
  out:
-  if (index_files)
-    g_ptr_array_unref (index_files);
-  if (ret_indexes)
-    g_ptr_array_unref (ret_indexes);
   return ret;
 }
 
@@ -1594,12 +1542,12 @@ list_pack_checksums_from_superindex_file (GFile         *superindex_path,
                                           GError       **error)
 {
   gboolean ret = FALSE;
-  GPtrArray *ret_indexes = NULL;
-  GVariant *superindex_variant = NULL;
-  GVariantIter *variant_iter = NULL;
   const char *magic;
-  GVariant *checksum;
-  GVariant *bloom;
+  ot_lptrarray GPtrArray *ret_indexes = NULL;
+  ot_lvariant GVariant *superindex_variant = NULL;
+  ot_lvariant GVariant *checksum = NULL;
+  ot_lvariant GVariant *bloom = NULL;
+  GVariantIter *variant_iter = NULL;
 
   if (!ot_util_variant_map (superindex_path, OSTREE_PACK_SUPER_INDEX_VARIANT_FORMAT,
                             &superindex_variant, error))
@@ -1620,15 +1568,14 @@ list_pack_checksums_from_superindex_file (GFile         *superindex_path,
   while (g_variant_iter_loop (variant_iter, "(@ay ay)",
                               &checksum, &bloom))
     g_ptr_array_add (ret_indexes, ostree_checksum_from_bytes (checksum));
+  checksum = NULL;
+  bloom = NULL;
 
   ret = TRUE;
   ot_transfer_out_value (out_indexes, &ret_indexes);
  out:
-  ot_clear_gvariant (&superindex_variant);
   if (variant_iter)
     g_variant_iter_free (variant_iter);
-  if (ret_indexes)
-    g_ptr_array_unref (ret_indexes);
   return ret;
 }
 
@@ -1640,8 +1587,8 @@ ostree_repo_list_pack_indexes (OstreeRepo              *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GFile *superindex_path = NULL;
-  GPtrArray *ret_indexes = NULL;
+  ot_lobj GFile *superindex_path = NULL;
+  ot_lptrarray GPtrArray *ret_indexes = NULL;
 
   superindex_path = g_file_get_child (priv->pack_dir, "index");
 
@@ -1658,9 +1605,6 @@ ostree_repo_list_pack_indexes (OstreeRepo              *self,
   ret = TRUE;
   ot_transfer_out_value (out_indexes, &ret_indexes);
  out:
-  g_clear_object (&superindex_path);
-  if (ret_indexes)
-    g_ptr_array_unref (ret_indexes);
   return ret;
 }
 
@@ -1672,7 +1616,7 @@ create_index_bloom (OstreeRepo          *self,
                     GError             **error)
 {
   gboolean ret = FALSE;
-  GVariant *ret_bloom;
+  ot_lvariant GVariant *ret_bloom;
 
   /* TODO - define and compute bloom filter */
 
@@ -1682,7 +1626,6 @@ create_index_bloom (OstreeRepo          *self,
   ret = TRUE;
   ot_transfer_out_value (out_bloom, &ret_bloom);
   /* out: */
-  ot_clear_gvariant (&ret_bloom);
   return ret;
 }
 
@@ -1696,12 +1639,12 @@ ostree_repo_regenerate_pack_index (OstreeRepo       *self,
                                    GError          **error)
 {
   gboolean ret = FALSE;
+  guint i;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GFile *index_path = NULL;
-  GPtrArray *pack_indexes = NULL;
+  ot_lobj GFile *index_path = NULL;
+  ot_lptrarray GPtrArray *pack_indexes = NULL;
+  ot_lvariant GVariant *index_variant = NULL;
   GVariantBuilder *index_content_builder = NULL;
-  GVariant *index_variant = NULL;
-  guint i;
 
   if (!list_pack_indexes_from_dir (self, &pack_indexes, cancellable, error))
     goto out;
@@ -1738,12 +1681,8 @@ ostree_repo_regenerate_pack_index (OstreeRepo       *self,
 
   ret = TRUE;
  out:
-  ot_clear_gvariant (&index_variant);
   if (index_content_builder)
     g_variant_builder_unref (index_content_builder);
-  g_clear_object (&index_path);
-  if (pack_indexes)
-    g_ptr_array_unref (pack_indexes);
   return ret;
 }
 
@@ -1770,8 +1709,8 @@ ostree_repo_add_pack_file (OstreeRepo       *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GFile *pack_index_path = NULL;
-  GFile *pack_data_path = NULL;
+  ot_lobj GFile *pack_index_path = NULL;
+  ot_lobj GFile *pack_data_path = NULL;
 
   if (!ot_gfile_ensure_directory (priv->pack_dir, FALSE, error))
     goto out;
@@ -1786,8 +1725,6 @@ ostree_repo_add_pack_file (OstreeRepo       *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&pack_index_path);
-  g_clear_object (&pack_data_path);
   return ret;
 }
 
@@ -1800,7 +1737,7 @@ ensure_remote_cache_dir (OstreeRepo       *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GFile *ret_cache_dir = NULL;
+  ot_lobj GFile *ret_cache_dir = NULL;
 
   ret_cache_dir = g_file_get_child (priv->remote_cache_dir, remote_name);
   
@@ -1810,7 +1747,6 @@ ensure_remote_cache_dir (OstreeRepo       *self,
   ret = TRUE;
   ot_transfer_out_value (out_cache_dir, &ret_cache_dir);
  out:
-  g_clear_object (&ret_cache_dir);
   return ret;
 }
 
@@ -1834,21 +1770,21 @@ ostree_repo_resync_cached_remote_pack_indexes (OstreeRepo       *self,
                                                GError          **error)
 {
   gboolean ret = FALSE;
-  GVariant *superindex_variant = NULL;
-  GVariantIter *superindex_contents_iter = NULL;
-  GFile *cache_path = NULL;
-  GFile *superindex_cache_path = NULL;
-  GPtrArray *index_files = NULL;
-  GPtrArray *data_files = NULL;
-  GHashTable *new_pack_indexes = NULL;
   GHashTableIter hash_iter;
   gpointer key, value;
-  GPtrArray *ret_cached_indexes = NULL;
-  GPtrArray *ret_uncached_indexes = NULL;
   guint i;
-  GVariant *csum_bytes = NULL;
-  GVariant *bloom = NULL;
-  char *pack_checksum = NULL;
+  ot_lvariant GVariant *superindex_variant = NULL;
+  ot_lobj GFile *cache_path = NULL;
+  ot_lobj GFile *superindex_cache_path = NULL;
+  ot_lptrarray GPtrArray *index_files = NULL;
+  ot_lptrarray GPtrArray *data_files = NULL;
+  ot_lhash GHashTable *new_pack_indexes = NULL;
+  ot_lptrarray GPtrArray *ret_cached_indexes = NULL;
+  ot_lptrarray GPtrArray *ret_uncached_indexes = NULL;
+  ot_lvariant GVariant *csum_bytes = NULL;
+  ot_lvariant GVariant *bloom = NULL;
+  ot_lfree char *pack_checksum = NULL;
+  GVariantIter *superindex_contents_iter = NULL;
 
   if (!ensure_remote_cache_dir (self, remote_name, &cache_path, cancellable, error))
     goto out;
@@ -1947,15 +1883,8 @@ ostree_repo_resync_cached_remote_pack_indexes (OstreeRepo       *self,
   ot_transfer_out_value (out_cached_indexes, &ret_cached_indexes);
   ot_transfer_out_value (out_uncached_indexes, &ret_uncached_indexes);
  out:
-  g_free (pack_checksum);
-  g_clear_object (&cache_path);
-  g_clear_object (&superindex_cache_path);
   if (superindex_contents_iter)
     g_variant_iter_free (superindex_contents_iter);
-  ot_clear_ptrarray (&ret_cached_indexes);
-  ot_clear_ptrarray (&ret_uncached_indexes);
-  ot_clear_hashtable (&new_pack_indexes);
-  ot_clear_ptrarray (&index_files);
   return ret;
 }
 
@@ -1966,9 +1895,9 @@ ostree_repo_clean_cached_remote_pack_data (OstreeRepo       *self,
                                            GError          **error)
 {
   gboolean ret = FALSE;
-  GFile *cache_path = NULL;
-  GPtrArray *data_files = NULL;
   guint i;
+  ot_lobj GFile *cache_path = NULL;
+  ot_lptrarray GPtrArray *data_files = NULL;
 
   if (!ensure_remote_cache_dir (self, remote_name, &cache_path, cancellable, error))
     goto out;
@@ -1989,8 +1918,6 @@ ostree_repo_clean_cached_remote_pack_data (OstreeRepo       *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&cache_path);
-  ot_clear_ptrarray (&data_files);
   return ret;
 }
 
@@ -2007,9 +1934,9 @@ ostree_repo_map_cached_remote_pack_index (OstreeRepo       *self,
                                           GError          **error)
 {
   gboolean ret = FALSE;
-  GVariant *ret_variant = NULL;
-  GFile *cache_dir = NULL;
-  GFile *cached_pack_path = NULL;
+  ot_lvariant GVariant *ret_variant = NULL;
+  ot_lobj GFile *cache_dir = NULL;
+  ot_lobj GFile *cached_pack_path = NULL;
 
   if (!ensure_remote_cache_dir (self, remote_name, &cache_dir,
                                 cancellable, error))
@@ -2023,9 +1950,6 @@ ostree_repo_map_cached_remote_pack_index (OstreeRepo       *self,
   ret = TRUE;
   ot_transfer_out_value (out_variant, &ret_variant);
  out:
-  g_clear_object (&cache_dir);
-  g_clear_object (&cached_pack_path);
-  ot_clear_gvariant (&ret_variant);
   return ret;
 }
 
@@ -2043,10 +1967,10 @@ ostree_repo_add_cached_remote_pack_index (OstreeRepo       *self,
                                           GError          **error)
 {
   gboolean ret = FALSE;
-  GFile *cachedir = NULL;
-  GFile *target_path = NULL;
-  GVariant *input_index_variant = NULL;
-  GVariant *output_index_variant = NULL;
+  ot_lobj GFile *cachedir = NULL;
+  ot_lobj GFile *target_path = NULL;
+  ot_lvariant GVariant *input_index_variant = NULL;
+  ot_lvariant GVariant *output_index_variant = NULL;
 
   if (!map_variant_file_check_header_string (cached_path,
                                              OSTREE_PACK_INDEX_VARIANT_FORMAT,
@@ -2069,10 +1993,6 @@ ostree_repo_add_cached_remote_pack_index (OstreeRepo       *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&cachedir);
-  g_clear_object (&target_path);
-  ot_clear_gvariant (&input_index_variant);
-  ot_clear_gvariant (&output_index_variant);
   return ret;
 }
 
@@ -2090,9 +2010,9 @@ ostree_repo_get_cached_remote_pack_data (OstreeRepo       *self,
                                          GError          **error)
 {
   gboolean ret = FALSE;
-  GFile *cache_dir = NULL;
-  GFile *cached_pack_path = NULL;
-  GFile *ret_cached_path = NULL;
+  ot_lobj GFile *cache_dir = NULL;
+  ot_lobj GFile *cached_pack_path = NULL;
+  ot_lobj GFile *ret_cached_path = NULL;
 
   if (!ensure_remote_cache_dir (self, remote_name, &cache_dir,
                                 cancellable, error))
@@ -2108,8 +2028,6 @@ ostree_repo_get_cached_remote_pack_data (OstreeRepo       *self,
   ret = TRUE;
   ot_transfer_out_value (out_cached_path, &ret_cached_path);
  out:
-  g_clear_object (&cache_dir);
-  g_clear_object (&cached_pack_path);
   return ret;
 }
 
@@ -2129,8 +2047,8 @@ ostree_repo_take_cached_remote_pack_data (OstreeRepo       *self,
                                           GError          **error)
 {
   gboolean ret = FALSE;
-  GFile *cachedir = NULL;
-  GFile *target_path = NULL;
+  ot_lobj GFile *cachedir = NULL;
+  ot_lobj GFile *target_path = NULL;
 
   if (!ensure_remote_cache_dir (self, remote_name, &cachedir, cancellable, error))
     goto out;
@@ -2142,8 +2060,6 @@ ostree_repo_take_cached_remote_pack_data (OstreeRepo       *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&cachedir);
-  g_clear_object (&target_path);
   return ret;
 }
 
@@ -2152,12 +2068,12 @@ create_tree_variant_from_hashes (GHashTable            *file_checksums,
                                  GHashTable            *dir_contents_checksums,
                                  GHashTable            *dir_metadata_checksums)
 {
+  GHashTableIter hash_iter;
+  gpointer key, value;
   GVariantBuilder files_builder;
   GVariantBuilder dirs_builder;
-  GHashTableIter hash_iter;
   GSList *sorted_filenames = NULL;
   GSList *iter;
-  gpointer key, value;
   GVariant *serialized_tree;
 
   g_variant_builder_init (&files_builder, G_VARIANT_TYPE ("a(ss)"));
@@ -2281,22 +2197,22 @@ stage_directory_to_mtree_internal (OstreeRepo           *self,
                                    GError              **error)
 {
   gboolean ret = FALSE;
-  OstreeRepoFile *repo_dir = NULL;
   GError *temp_error = NULL;
-  GFileInfo *child_info = NULL;
-  OstreeMutableTree *child_mtree = NULL;
-  GFileEnumerator *dir_enum = NULL;
-  GFileInfo *modified_info = NULL;
-  GFile *child = NULL;
-  GChecksum *child_file_checksum = NULL;
-  GVariant *xattrs = NULL;
-  GInputStream *file_input = NULL;
   gboolean repo_dir_was_empty = FALSE;
   OstreeRepoCommitFilterResult filter_result;
+  ot_lobj OstreeRepoFile *repo_dir = NULL;
+  ot_lobj GFileInfo *child_info = NULL;
+  ot_lobj OstreeMutableTree *child_mtree = NULL;
+  ot_lobj GFileEnumerator *dir_enum = NULL;
+  ot_lobj GFileInfo *modified_info = NULL;
+  ot_lobj GFile *child = NULL;
+  ot_lvariant GVariant *xattrs = NULL;
+  ot_lobj GInputStream *file_input = NULL;
+  GChecksum *child_file_checksum = NULL;
 
   /* We can only reuse checksums directly if there's no modifier */
   if (OSTREE_IS_REPO_FILE (dir) && modifier == NULL)
-    repo_dir = (OstreeRepoFile*)dir;
+    repo_dir = (OstreeRepoFile*)g_object_ref (dir);
 
   if (repo_dir)
     {
@@ -2425,14 +2341,7 @@ stage_directory_to_mtree_internal (OstreeRepo           *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&dir_enum);
-  g_clear_object (&child);
-  g_clear_object (&modified_info);
-  g_clear_object (&child_info);
-  g_clear_object (&file_input);
-  g_clear_object (&child_mtree);
   ot_clear_checksum (&child_file_checksum);
-  ot_clear_gvariant (&xattrs);
   return ret;
 }
 
@@ -2466,14 +2375,14 @@ ostree_repo_stage_mtree (OstreeRepo           *self,
                          GError              **error)
 {
   gboolean ret = FALSE;
-  GChecksum *ret_contents_checksum_obj = NULL;
-  char *ret_contents_checksum = NULL;
-  GHashTable *dir_metadata_checksums = NULL;
-  GHashTable *dir_contents_checksums = NULL;
-  GVariant *serialized_tree = NULL;
   GHashTableIter hash_iter;
   gpointer key, value;
   const char *existing_checksum;
+  ot_lfree char *ret_contents_checksum = NULL;
+  ot_lhash GHashTable *dir_metadata_checksums = NULL;
+  ot_lhash GHashTable *dir_contents_checksums = NULL;
+  ot_lvariant GVariant *serialized_tree = NULL;
+  GChecksum *ret_contents_checksum_obj = NULL;
 
   existing_checksum = ostree_mutable_tree_get_contents_checksum (mtree);
   if (existing_checksum)
@@ -2522,13 +2431,7 @@ ostree_repo_stage_mtree (OstreeRepo           *self,
   ret = TRUE;
   ot_transfer_out_value(out_contents_checksum, &ret_contents_checksum);
  out:
-  if (dir_contents_checksums)
-    g_hash_table_destroy (dir_contents_checksums);
-  if (dir_metadata_checksums)
-    g_hash_table_destroy (dir_metadata_checksums);
-  g_free (ret_contents_checksum);
   ot_clear_checksum (&ret_contents_checksum_obj);
-  ot_clear_gvariant (&serialized_tree);
   return ret;
 }
 
@@ -2590,7 +2493,7 @@ import_libarchive_entry_file (OstreeRepo           *self,
                               GError              **error)
 {
   gboolean ret = FALSE;
-  GInputStream *archive_stream = NULL;
+  ot_lobj GInputStream *archive_stream = NULL;
   GChecksum *ret_checksum = NULL;
   
   if (g_cancellable_set_error_if_cancelled (cancellable, error))
@@ -2608,7 +2511,6 @@ import_libarchive_entry_file (OstreeRepo           *self,
   ret = TRUE;
   ot_transfer_out_value(out_checksum, &ret_checksum);
  out:
-  g_clear_object (&archive_stream);
   ot_clear_checksum (&ret_checksum);
   return ret;
 }
@@ -2627,15 +2529,15 @@ stage_libarchive_entry_to_mtree (OstreeRepo           *self,
   const char *pathname;
   const char *hardlink;
   const char *basename;
-  GFileInfo *file_info = NULL;
+  ot_lobj GFileInfo *file_info = NULL;
+  ot_lptrarray GPtrArray *split_path = NULL;
+  ot_lptrarray GPtrArray *hardlink_split_path = NULL;
+  ot_lobj OstreeMutableTree *subdir = NULL;
+  ot_lobj OstreeMutableTree *parent = NULL;
+  ot_lobj OstreeMutableTree *hardlink_source_parent = NULL;
+  ot_lfree char *hardlink_source_checksum = NULL;
+  ot_lobj OstreeMutableTree *hardlink_source_subdir = NULL;
   GChecksum *tmp_checksum = NULL;
-  GPtrArray *split_path = NULL;
-  GPtrArray *hardlink_split_path = NULL;
-  OstreeMutableTree *subdir = NULL;
-  OstreeMutableTree *parent = NULL;
-  OstreeMutableTree *hardlink_source_parent = NULL;
-  char *hardlink_source_checksum = NULL;
-  OstreeMutableTree *hardlink_source_subdir = NULL;
 
   pathname = archive_entry_pathname (entry); 
       
@@ -2760,17 +2662,7 @@ stage_libarchive_entry_to_mtree (OstreeRepo           *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&file_info);
   ot_clear_checksum (&tmp_checksum);
-  g_clear_object (&parent);
-  g_clear_object (&subdir);
-  g_clear_object (&hardlink_source_parent);
-  g_free (hardlink_source_checksum);
-  g_clear_object (&hardlink_source_subdir);
-  if (hardlink_split_path)
-    g_ptr_array_unref (hardlink_split_path);
-  if (split_path)
-    g_ptr_array_unref (split_path);
   return ret;
 }
 #endif
@@ -2789,7 +2681,7 @@ ostree_repo_stage_archive_to_mtree (OstreeRepo                *self,
   struct archive *a = NULL;
   struct archive_entry *entry;
   int r;
-  GFileInfo *tmp_dir_info = NULL;
+  ot_lobj GFileInfo *tmp_dir_info = NULL;
   GChecksum *tmp_dir_checksum = NULL;
 
   a = archive_read_new ();
@@ -2838,7 +2730,6 @@ ostree_repo_stage_archive_to_mtree (OstreeRepo                *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&tmp_dir_info);
   ot_clear_checksum (&tmp_dir_checksum);
   if (a)
     (void)archive_read_close (a);
@@ -2881,10 +2772,10 @@ list_loose_object_dir (OstreeRepo             *self,
 {
   gboolean ret = FALSE;
   GError *temp_error = NULL;
-  GFileEnumerator *enumerator = NULL;
-  GFileInfo *file_info = NULL;
   const char *dirname = NULL;
-  char *dot = NULL;
+  const char *dot = NULL;
+  ot_lobj GFileEnumerator *enumerator = NULL;
+  ot_lobj GFileInfo *file_info = NULL;
   GString *checksum = NULL;
 
   dirname = ot_gfile_get_basename_cached (dir);
@@ -2956,8 +2847,6 @@ list_loose_object_dir (OstreeRepo             *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&file_info);
-  g_clear_object (&enumerator);
   if (checksum)
     g_string_free (checksum, TRUE);
   return ret;
@@ -2971,10 +2860,10 @@ list_loose_objects (OstreeRepo                     *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GFileEnumerator *enumerator = NULL;
-  GFileInfo *file_info = NULL;
   GError *temp_error = NULL;
-  GFile *objdir = NULL;
+  ot_lobj GFileEnumerator *enumerator = NULL;
+  ot_lobj GFileInfo *file_info = NULL;
+  ot_lobj GFile *objdir = NULL;
 
   enumerator = g_file_enumerate_children (priv->objects_dir, OSTREE_GIO_FAST_QUERYINFO, 
                                           G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -3010,9 +2899,6 @@ list_loose_objects (OstreeRepo                     *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&objdir);
-  g_clear_object (&file_info);
-  g_clear_object (&enumerator);
   return ret;
 }
 
@@ -3053,8 +2939,8 @@ ostree_repo_load_pack_index (OstreeRepo    *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GVariant *ret_variant = NULL;
-  GFile *path = NULL;
+  ot_lvariant GVariant *ret_variant = NULL;
+  ot_lobj GFile *path = NULL;
   
   ret_variant = g_hash_table_lookup (priv->pack_index_mappings, sha256);
   if (ret_variant)
@@ -3077,8 +2963,6 @@ ostree_repo_load_pack_index (OstreeRepo    *self,
   ret = TRUE;
   ot_transfer_out_value (out_variant, &ret_variant);
  out:
-  g_clear_object (&path);
-  ot_clear_gvariant (&ret_variant);
   return ret;
 }
 
@@ -3103,10 +2987,10 @@ ostree_repo_map_pack_file (OstreeRepo    *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GMappedFile *map;
   gpointer ret_data;
   guint64 ret_len;
-  GFile *path = NULL;
+  GMappedFile *map = NULL;
+  ot_lobj GFile *path = NULL;
 
   map = g_hash_table_lookup (priv->pack_data_mappings, sha256);
   if (map == NULL)
@@ -3130,7 +3014,6 @@ ostree_repo_map_pack_file (OstreeRepo    *self,
   if (out_len)
     *out_len = ret_len;
  out:
-  g_clear_object (&path);
   return ret;
 }
 
@@ -3145,17 +3028,17 @@ ostree_repo_load_file (OstreeRepo         *self,
                        GError            **error)
 {
   gboolean ret = FALSE;
-  GVariant *archive_meta = NULL;
-  GFile *content_loose_path = NULL;
-  GFileInfo *content_loose_info = NULL;
-  char *content_pack_checksum = NULL;
-  guint64 content_pack_offset;
   guchar *content_pack_data;
   guint64 content_pack_len;
-  GVariant *packed_object = NULL;
-  GInputStream *ret_input = NULL;
-  GFileInfo *ret_file_info = NULL;
-  GVariant *ret_xattrs = NULL;
+  guint64 content_pack_offset;
+  ot_lvariant GVariant *packed_object = NULL;
+  ot_lvariant GVariant *archive_meta = NULL;
+  ot_lobj GFile *content_loose_path = NULL;
+  ot_lobj GFileInfo *content_loose_info = NULL;
+  ot_lfree char *content_pack_checksum = NULL;
+  ot_lobj GInputStream *ret_input = NULL;
+  ot_lobj GFileInfo *ret_file_info = NULL;
+  ot_lvariant GVariant *ret_xattrs = NULL;
 
   if (ostree_repo_get_mode (self) == OSTREE_REPO_MODE_ARCHIVE)
     {
@@ -3247,14 +3130,6 @@ ostree_repo_load_file (OstreeRepo         *self,
   ot_transfer_out_value (out_file_info, &ret_file_info);
   ot_transfer_out_value (out_xattrs, &ret_xattrs);
  out:
-  g_free (content_pack_checksum);
-  g_clear_object (&ret_input);
-  g_clear_object (&content_loose_path);
-  g_clear_object (&content_loose_info);
-  g_clear_object (&ret_file_info);
-  ot_clear_gvariant (&ret_xattrs);
-  ot_clear_gvariant (&archive_meta);
-  ot_clear_gvariant (&packed_object);
   return ret;
 }
 
@@ -3266,14 +3141,14 @@ list_objects_in_index (OstreeRepo                     *self,
                        GError                        **error)
 {
   gboolean ret = FALSE;
-  GFile *index_path = NULL;
-  GVariant *index_variant = NULL;
-  GVariant *contents;
-  GVariantIter content_iter;
-  GVariant *csum_bytes;
-  char *checksum = NULL;
   guint32 objtype_u32;
   guint64 offset;
+  ot_lobj GFile *index_path = NULL;
+  ot_lvariant GVariant *index_variant = NULL;
+  ot_lvariant GVariant *contents;
+  ot_lvariant GVariant *csum_bytes;
+  ot_lfree char *checksum = NULL;
+  GVariantIter content_iter;
 
   index_path = ostree_repo_get_pack_index_path (self, pack_checksum);
 
@@ -3329,10 +3204,6 @@ list_objects_in_index (OstreeRepo                     *self,
 
   ret = TRUE;
  out:
-  g_free (checksum);
-  g_clear_object (&index_path);
-  ot_clear_gvariant (&index_variant);
-  ot_clear_gvariant (&contents);
   return ret;
 }
 
@@ -3343,8 +3214,8 @@ list_packed_objects (OstreeRepo                     *self,
                      GError                        **error)
 {
   gboolean ret = FALSE;
-  GPtrArray *index_checksums = NULL;
   guint i;
+  ot_lptrarray GPtrArray *index_checksums = NULL;
 
   if (!ostree_repo_list_pack_indexes (self, &index_checksums, cancellable, error))
     goto out;
@@ -3359,8 +3230,6 @@ list_packed_objects (OstreeRepo                     *self,
   
   ret = TRUE;
  out:
-  if (index_checksums)
-    g_ptr_array_unref (index_checksums);
   return ret;
 }
 
@@ -3374,13 +3243,13 @@ find_object_in_packs (OstreeRepo        *self,
                       GError           **error)
 {
   gboolean ret = FALSE;
-  GPtrArray *index_checksums = NULL;
-  char *ret_pack_checksum = NULL;
-  guint64 ret_pack_offset;
-  GFile *index_path = NULL;
-  GVariant *csum_bytes = NULL;
-  GVariant *index_variant = NULL;
   guint i;
+  guint64 ret_pack_offset;
+  ot_lptrarray GPtrArray *index_checksums = NULL;
+  ot_lfree char *ret_pack_checksum = NULL;
+  ot_lobj GFile *index_path = NULL;
+  ot_lvariant GVariant *csum_bytes = NULL;
+  ot_lvariant GVariant *index_variant = NULL;
 
   csum_bytes = ostree_checksum_to_bytes (checksum);
 
@@ -3412,12 +3281,6 @@ find_object_in_packs (OstreeRepo        *self,
   if (out_pack_offset)
     *out_pack_offset = ret_pack_offset;
  out:
-  g_free (ret_pack_checksum);
-  if (index_checksums)
-    g_ptr_array_unref (index_checksums);
-  g_clear_object (&index_path);
-  ot_clear_gvariant (&index_variant);
-  ot_clear_gvariant (&csum_bytes);
   return ret;
 }
 
@@ -3432,11 +3295,11 @@ ostree_repo_find_object (OstreeRepo           *self,
                          GError             **error)
 {
   gboolean ret = FALSE;
-  GFile *object_path = NULL;
-  GFile *ret_stored_path = NULL;
-  char *ret_pack_checksum = NULL;
   guint64 ret_pack_offset = 0;
   struct stat stbuf;
+  ot_lobj GFile *object_path = NULL;
+  ot_lobj GFile *ret_stored_path = NULL;
+  ot_lfree char *ret_pack_checksum = NULL;
 
   object_path = ostree_repo_get_object_path (self, checksum, objtype);
   
@@ -3464,9 +3327,6 @@ ostree_repo_find_object (OstreeRepo           *self,
   if (out_pack_offset)
     *out_pack_offset = ret_pack_offset;
 out:
-  g_clear_object (&object_path);
-  g_clear_object (&ret_stored_path);
-  g_free (ret_pack_checksum);
   return ret;
 }
 
@@ -3478,14 +3338,14 @@ ostree_repo_load_variant (OstreeRepo  *self,
                           GError       **error)
 {
   gboolean ret = FALSE;
-  GFile *object_path = NULL;
-  GVariant *packed_object = NULL;
-  GVariant *ret_variant = NULL;
-  char *pack_checksum = NULL;
   guchar *pack_data;
   guint64 pack_len;
   guint64 object_offset;
   GCancellable *cancellable = NULL;
+  ot_lobj GFile *object_path = NULL;
+  ot_lvariant GVariant *packed_object = NULL;
+  ot_lvariant GVariant *ret_variant = NULL;
+  ot_lfree char *pack_checksum = NULL;
 
   g_return_val_if_fail (OSTREE_OBJECT_TYPE_IS_META (objtype), FALSE);
 
@@ -3525,10 +3385,6 @@ ostree_repo_load_variant (OstreeRepo  *self,
   ret = TRUE;
   ot_transfer_out_value (out_variant, &ret_variant);
  out:
-  g_clear_object (&object_path);
-  g_free (pack_checksum);
-  ot_clear_gvariant (&ret_variant);
-  ot_clear_gvariant (&packed_object);
   return ret;
 }
 
@@ -3556,7 +3412,7 @@ ostree_repo_list_objects (OstreeRepo                  *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GHashTable *ret_objects = NULL;
+  ot_lhash GHashTable *ret_objects = NULL;
 
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
   g_return_val_if_fail (priv->inited, FALSE);
@@ -3583,8 +3439,6 @@ ostree_repo_list_objects (OstreeRepo                  *self,
   ret = TRUE;
   ot_transfer_out_value (out_objects, &ret_objects);
  out:
-  if (ret_objects)
-    g_hash_table_unref (ret_objects);
   return ret;
 }
 
@@ -3600,9 +3454,9 @@ checkout_file_from_input (GFile          *file,
 {
   gboolean ret = FALSE;
   GError *temp_error = NULL;
-  GFile *dir = NULL;
-  GFile *temp_file = NULL;
-  GFileInfo *temp_info = NULL;
+  ot_lobj GFile *dir = NULL;
+  ot_lobj GFile *temp_file = NULL;
+  ot_lobj GFileInfo *temp_info = NULL;
 
   if (mode == OSTREE_REPO_CHECKOUT_MODE_USER)
     {
@@ -3663,9 +3517,6 @@ checkout_file_from_input (GFile          *file,
 
   ret = TRUE;
  out:
-  g_clear_object (&temp_info);
-  g_clear_object (&temp_file);
-  g_clear_object (&dir);
   return ret;
 }
 
@@ -3679,8 +3530,8 @@ checkout_file_hardlink (OstreeRepo                  *self,
                         GError                  **error)
 {
   gboolean ret = FALSE;
-  GFile *dir = NULL;
-  GFile *temp_file = NULL;
+  ot_lobj GFile *dir = NULL;
+  ot_lobj GFile *temp_file = NULL;
 
   if (overwrite_mode == OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES)
     {
@@ -3719,10 +3570,8 @@ checkout_file_hardlink (OstreeRepo                  *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&dir);
   if (temp_file)
     (void) unlink (ot_gfile_get_path_cached (temp_file));
-  g_clear_object (&temp_file);
   return ret;
 }
 
@@ -3738,11 +3587,11 @@ checkout_one_file (OstreeRepo                  *self,
 {
   gboolean ret = FALSE;
   OstreeRepoPrivate *priv = GET_PRIVATE (self);
-  GFile *possible_loose_path = NULL;
-  GInputStream *input = NULL;
-  GVariant *xattrs = NULL;
   const char *checksum;
   struct stat stbuf;
+  ot_lobj GFile *possible_loose_path = NULL;
+  ot_lobj GInputStream *input = NULL;
+  ot_lvariant GVariant *xattrs = NULL;
 
   checksum = ostree_repo_file_get_checksum ((OstreeRepoFile*)src);
 
@@ -3775,9 +3624,6 @@ checkout_one_file (OstreeRepo                  *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&possible_loose_path);
-  g_clear_object (&input);
-  ot_clear_gvariant (&xattrs);
   return ret;
 }
 
@@ -3793,11 +3639,11 @@ ostree_repo_checkout_tree (OstreeRepo               *self,
 {
   gboolean ret = FALSE;
   GError *temp_error = NULL;
-  GFileInfo *file_info = NULL;
-  GVariant *xattrs = NULL;
-  GFileEnumerator *dir_enum = NULL;
-  GFile *src_child = NULL;
-  GFile *dest_path = NULL;
+  ot_lobj GFileInfo *file_info = NULL;
+  ot_lvariant GVariant *xattrs = NULL;
+  ot_lobj GFileEnumerator *dir_enum = NULL;
+  ot_lobj GFile *src_child = NULL;
+  ot_lobj GFile *dest_path = NULL;
 
   if (!ostree_repo_file_get_xattrs (source, &xattrs, NULL, error))
     goto out;
@@ -3855,12 +3701,6 @@ ostree_repo_checkout_tree (OstreeRepo               *self,
 
   ret = TRUE;
  out:
-  g_clear_object (&dir_enum);
-  g_clear_object (&file_info);
-  ot_clear_gvariant (&xattrs);
-  g_clear_object (&src_child);
-  g_clear_object (&dest_path);
-  g_free (dest_path);
   return ret;
 }
 
@@ -3872,8 +3712,8 @@ ostree_repo_read_commit (OstreeRepo *self,
                          GError **error)
 {
   gboolean ret = FALSE;
-  GFile *ret_root = NULL;
-  char *resolved_rev = NULL;
+  ot_lobj GFile *ret_root = NULL;
+  ot_lfree char *resolved_rev = NULL;
 
   if (!ostree_repo_resolve_rev (self, rev, FALSE, &resolved_rev, error))
     goto out;
@@ -3885,7 +3725,5 @@ ostree_repo_read_commit (OstreeRepo *self,
   ret = TRUE;
   ot_transfer_out_value(out_root, &ret_root);
  out:
-  g_free (resolved_rev);
-  g_clear_object (&ret_root);
   return ret;
 }
diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c
index cb0ede4..121c31d 100644
--- a/src/libostree/ostree-sysroot.c
+++ b/src/libostree/ostree-sysroot.c
@@ -59,9 +59,9 @@ ostree_run_triggers_in_root (GFile                  *root,
 {
   gboolean ret = FALSE;
   int estatus;
-  char *rel_triggerdir = NULL;
-  GFile *triggerdir = NULL;
-  GPtrArray *argv = NULL;
+  ot_lfree char *rel_triggerdir = NULL;
+  ot_lobj GFile *triggerdir = NULL;
+  ot_lptrarray GPtrArray *argv = NULL;
 
   rel_triggerdir = g_build_filename ("usr", "libexec", "ostree", "triggers.d", NULL);
 
@@ -114,8 +114,5 @@ ostree_run_triggers_in_root (GFile                  *root,
 
   ret = TRUE;
  out:
-  g_free (rel_triggerdir);
-  g_clear_object (&triggerdir);
-  ot_clear_ptrarray (&argv);
   return ret;
 }
diff --git a/src/libostree/ostree-traverse.c b/src/libostree/ostree-traverse.c
index a207fad..f1f1661 100644
--- a/src/libostree/ostree-traverse.c
+++ b/src/libostree/ostree-traverse.c
@@ -42,11 +42,11 @@ ostree_traverse_dirtree (OstreeRepo      *repo,
                          GError         **error)
 {
   gboolean ret = FALSE;
-  GVariant *tree = NULL;
-  GVariant *files_variant = NULL;
-  GVariant *dirs_variant = NULL;
   int n, i;
-  GVariant *key;
+  ot_lvariant GVariant *key;
+  ot_lvariant GVariant *tree = NULL;
+  ot_lvariant GVariant *files_variant = NULL;
+  ot_lvariant GVariant *dirs_variant = NULL;
 
   if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, dirtree_checksum, &tree, error))
     goto out;
@@ -105,10 +105,6 @@ ostree_traverse_dirtree (OstreeRepo      *repo,
 
   ret = TRUE;
  out:
-  ot_clear_gvariant (&key);
-  ot_clear_gvariant (&tree);
-  ot_clear_gvariant (&files_variant);
-  ot_clear_gvariant (&dirs_variant);
   return ret;
 }
 
@@ -121,10 +117,10 @@ ostree_traverse_commit (OstreeRepo      *repo,
                         GError         **error)
 {
   gboolean ret = FALSE;
-  GVariant *commit = NULL;
   const char *contents_checksum;
   const char *meta_checksum;
-  GVariant *key;
+  ot_lvariant GVariant *key;
+  ot_lvariant GVariant *commit = NULL;
 
   /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */
   if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, &commit, error))
@@ -132,10 +128,12 @@ ostree_traverse_commit (OstreeRepo      *repo,
   
   key = ostree_object_name_serialize (commit_checksum, OSTREE_OBJECT_TYPE_COMMIT);
   g_hash_table_replace (inout_reachable, key, key);
+  key = NULL;
 
   g_variant_get_child (commit, 7, "&s", &meta_checksum);
   key = ostree_object_name_serialize (meta_checksum, OSTREE_OBJECT_TYPE_DIR_META);
   g_hash_table_replace (inout_reachable, key, key);
+  key = NULL;
 
   g_variant_get_child (commit, 6, "&s", &contents_checksum);
   if (!ostree_traverse_dirtree (repo, contents_checksum, inout_reachable, cancellable, error))
@@ -158,7 +156,6 @@ ostree_traverse_commit (OstreeRepo      *repo,
 
   ret = TRUE;
  out:
-  ot_clear_gvariant (&commit);
   return ret;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]