Some more memory leak avoidance
authorLinus Torvalds <torvalds@osdl.org>
Sun, 18 Jun 2006 01:47:58 +0000 (18:47 -0700)
committerJunio C Hamano <junkio@cox.net>
Sun, 18 Jun 2006 01:49:52 +0000 (18:49 -0700)
This is really the dregs of my effort to not waste memory in git-rev-list,
and makes barely one percent of a difference in the memory footprint, but
hey, it's also a pretty small patch.

It discards the parent lists and the commit buffer after the commit has
been shown by git-rev-list (and "git log" - which already did the commit
buffer part), and frees the commit list entry that was used by the
revision walker.

The big win would be to get rid of the "refs" pointer in the object
structure (another 5%), because it's only used by fsck. That would require
some pretty major surgery to fsck, though, so I'm timid and did the less
interesting but much easier part instead.

This (percentually) makes a bigger difference to "git log" and friends,
since those are walking _just_ commits, and thus the list entries tend to
be a bigger percentage of the memory use. But the "list all objects" case
does improve too.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-log.c
builtin-rev-list.c
revision.c
index f4d974a7b8bfa0472a110273edf62b34b90902fe..6afa66ce02bee9a0de4403e1bfb0eedb70c087df 100644 (file)
@@ -40,6 +40,8 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
                log_tree_commit(rev, commit);
                free(commit->buffer);
                commit->buffer = NULL;
+               free_commit_list(commit->parents);
+               commit->parents = NULL;
        }
        return 0;
 }
index 2b298c4e412c4fca24ea5068f17a557f89a6a449..71353eb19db158a60a5ae94f83f53059adc3399b 100644 (file)
@@ -89,6 +89,14 @@ static void show_commit(struct commit *commit)
                printf("%s%c", pretty_header, hdr_termination);
        }
        fflush(stdout);
+       if (commit->parents) {
+               free_commit_list(commit->parents);
+               commit->parents = NULL;
+       }
+       if (commit->buffer) {
+               free(commit->buffer);
+               commit->buffer = NULL;
+       }
 }
 
 static struct object_list **process_blob(struct blob *blob,
index 82214eb71a96e75089dbe583eb4e2d06eb608550..7bff2a10b1044651a776b42d4ee3d91661830aa2 100644 (file)
@@ -949,9 +949,11 @@ struct commit *get_revision(struct rev_info *revs)
        }
 
        do {
-               struct commit *commit = revs->commits->item;
+               struct commit_list *entry = revs->commits;
+               struct commit *commit = entry->item;
 
-               revs->commits = revs->commits->next;
+               revs->commits = entry->next;
+               free(entry);
 
                /*
                 * If we haven't done the list limiting, we need to look at