Revert "[PATCH] plug memory leak in diff.c::diff_free_filepair()"
authorJunio C Hamano <junkio@cox.net>
Wed, 14 Sep 2005 21:06:50 +0000 (14:06 -0700)
committerJunio C Hamano <junkio@cox.net>
Wed, 14 Sep 2005 21:06:50 +0000 (14:06 -0700)
This reverts 068eac91ce04b9aca163acb1927c3878c45d1a07 commit.

diff.c
diffcore-break.c
diffcore.h
diff --git a/diff.c b/diff.c
index 1059049fb99ae45fcfb81f3bf9ebb19005c67561..05a0663d4dc0a90a35535f00527a4dae38326526 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -402,13 +402,14 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
        return 0;
 }
 
-void diff_free_filespec(struct diff_filespec *s)
+void diff_free_filespec_data(struct diff_filespec *s)
 {
        if (s->should_free)
                free(s->data);
        else if (s->should_munmap)
                munmap(s->data, s->size);
-       free(s);
+       s->should_free = s->should_munmap = 0;
+       s->data = NULL;
 }
 
 static void prep_temp_blob(struct diff_tempfile *temp,
@@ -767,8 +768,8 @@ struct diff_filepair *diff_queue(struct diff_queue_struct *queue,
 
 void diff_free_filepair(struct diff_filepair *p)
 {
-       diff_free_filespec(p->one);
-       diff_free_filespec(p->two);
+       diff_free_filespec_data(p->one);
+       diff_free_filespec_data(p->two);
        free(p);
 }
 
index b0c8461e1243328795258f0fd7d12f509403403c..06f9a7f0ee25891ff6f4dd9646e39cd4c8b105fd 100644 (file)
@@ -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(d->two);
-       diff_free_filespec(c->one);
+       diff_free_filespec_data(d->two);
+       diff_free_filespec_data(c->one);
        free(d);
        free(c);
 }
index 633d1ae5cf708cca4b907f0f032294f78d7bbe18..f1b5ca748cae8d40f599552c3605080808da7803 100644 (file)
@@ -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(struct diff_filespec *);
+extern void diff_free_filespec_data(struct diff_filespec *);
 
 struct diff_filepair {
        struct diff_filespec *one;