[ostree/wip/libsysroot: 5/9] sysroot: Avoid bad double-free



commit 1641ade72822ea4d88c87c95584f2f286e0175ef
Author: Colin Walters <walters verbum org>
Date:   Thu Oct 3 18:30:07 2013 -0400

    sysroot: Avoid bad double-free
    
    If a deployment is somehow in the list twice, the hash table will free
    the *new* value with g_hash_table_insert which gets all broken.  Just
    use g_hash_table_replace().

 src/libostree/ostree-sysroot-cleanup.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/src/libostree/ostree-sysroot-cleanup.c b/src/libostree/ostree-sysroot-cleanup.c
index 884597b..ade75bb 100644
--- a/src/libostree/ostree-sysroot-cleanup.c
+++ b/src/libostree/ostree-sysroot-cleanup.c
@@ -304,7 +304,7 @@ cleanup_old_deployments (OstreeSysroot       *self,
                                    cancellable, error))
     goto out;
 
-  active_deployment_dirs = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, NULL, 
g_object_unref);
+  active_deployment_dirs = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, 
NULL);
   active_boot_checksums = g_hash_table_new_full (g_str_hash, (GEqualFunc)g_str_equal, g_free, NULL);
 
   for (i = 0; i < self->deployments->len; i++)
@@ -313,8 +313,8 @@ cleanup_old_deployments (OstreeSysroot       *self,
       GFile *deployment_path = ostree_sysroot_get_deployment_directory (self, deployment);
       char *bootcsum = g_strdup (ostree_deployment_get_bootcsum (deployment));
       /* Transfer ownership */
-      g_hash_table_insert (active_deployment_dirs, deployment_path, deployment_path);
-      g_hash_table_insert (active_boot_checksums, bootcsum, bootcsum);
+      g_hash_table_replace (active_deployment_dirs, deployment_path, deployment_path);
+      g_hash_table_replace (active_boot_checksums, bootcsum, bootcsum);
     }
 
   if (!list_all_deployment_directories (self, &all_deployment_dirs,


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