]> git.proxmox.com Git - libgit2.git/commitdiff
refs: don't leak the packref when deleting/renaming
authorCarlos Martín Nieto <carlos@cmartin.tk>
Thu, 19 Jan 2012 18:09:47 +0000 (19:09 +0100)
committerCarlos Martín Nieto <carlos@cmartin.tk>
Thu, 19 Jan 2012 18:09:47 +0000 (19:09 +0100)
When we remove the ref from the hashtable, we need to free the
packref.

src/refs.c

index 340841cc6859daf9827ca2de58e4754dada18ef9..86e5f5dba55e42a54ecf4d14904ba49699d48a74 100644 (file)
@@ -984,14 +984,16 @@ static int reference_delete(git_reference *ref)
         * We need to reload the packfile, remove the reference from the
         * packing list, and repack */
        if (ref->flags & GIT_REF_PACKED) {
+               struct packref *packref;
                /* load the existing packfile */
                if ((error = packed_load(ref->owner)) < GIT_SUCCESS)
                        return git__rethrow(error, "Failed to delete reference");
 
-               if (git_hashtable_remove(ref->owner->references.packfile,
-                               ref->name) < GIT_SUCCESS)
+               if (git_hashtable_remove2(ref->owner->references.packfile,
+                               ref->name, (void **) &packref) < GIT_SUCCESS)
                        return git__throw(GIT_ENOTFOUND, "Reference not found");
 
+               git__free (packref);
                error = packed_write(ref->owner);
 
        /* If the reference is loose, we can just remove the reference