提交 068eac91 编写于 作者: Y Yasushi SHOJI 提交者: Junio C Hamano

[PATCH] plug memory leak in diff.c::diff_free_filepair()

When I run git-diff-tree on big change, it seems the command eats so
much memory.  so I just put git under valgrind to see what's going on.
diff_free_filespec_data() doesn't free diff_filespec itself.

[jc: I ended up doing things slightly differently from Yasushi's
patch.  The original idea was to use free_filespec_data() only to
free the data portion and keep useing the filespec itself, but
no existing code seems to do things that way, so I just yanked
that part out.]
Signed-off-by: NYasushi SHOJI <yashi@atmark-techno.com>
Signed-off-by: NJunio C Hamano <junkio@cox.net>
上级 e54c5ea9
......@@ -405,14 +405,13 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
return 0;
}
void diff_free_filespec_data(struct diff_filespec *s)
void diff_free_filespec(struct diff_filespec *s)
{
if (s->should_free)
free(s->data);
else if (s->should_munmap)
munmap(s->data, s->size);
s->should_free = s->should_munmap = 0;
s->data = NULL;
free(s);
}
static void prep_temp_blob(struct diff_tempfile *temp,
......@@ -769,8 +768,8 @@ struct diff_filepair *diff_queue(struct diff_queue_struct *queue,
void diff_free_filepair(struct diff_filepair *p)
{
diff_free_filespec_data(p->one);
diff_free_filespec_data(p->two);
diff_free_filespec(p->one);
diff_free_filespec(p->two);
free(p);
}
......
......@@ -231,8 +231,8 @@ static void merge_broken(struct diff_filepair *p,
dp = diff_queue(outq, d->one, c->two);
dp->score = p->score;
diff_free_filespec_data(d->two);
diff_free_filespec_data(c->one);
diff_free_filespec(d->two);
diff_free_filespec(c->one);
free(d);
free(c);
}
......
......@@ -43,7 +43,7 @@ extern void fill_filespec(struct diff_filespec *, const unsigned char *,
unsigned short);
extern int diff_populate_filespec(struct diff_filespec *, int);
extern void diff_free_filespec_data(struct diff_filespec *);
extern void diff_free_filespec(struct diff_filespec *);
struct diff_filepair {
struct diff_filespec *one;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册