[PATCH] Introduce diff_free_filepair() funcion.
authorJunio C Hamano <junkio@cox.net>
Fri, 27 May 2005 22:50:30 +0000 (15:50 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Sun, 29 May 2005 18:17:43 +0000 (11:17 -0700)
This introduces a new function to free a common data structure,
and plugs some leaks.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
diff.c
diffcore-pathspec.c
diffcore-pickaxe.c
diffcore-rename.c
diffcore.h

diff --git a/diff.c b/diff.c
index f745cdd..680b521 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -521,6 +521,13 @@ struct diff_filepair *diff_queue(struct diff_queue_struct *queue,
        return dp;
 }
 
+void diff_free_filepair(struct diff_filepair *p)
+{
+       diff_free_filespec_data(p->one);
+       diff_free_filespec_data(p->two);
+       free(p);
+}
+
 static void diff_flush_raw(struct diff_filepair *p,
                           int line_termination,
                           int inter_name_termination)
@@ -817,12 +824,8 @@ void diff_flush(int diff_output_style, int resolve_rename_copy)
                        break;
                }
        }
-       for (i = 0; i < q->nr; i++) {
-               struct diff_filepair *p = q->queue[i];
-               diff_free_filespec_data(p->one);
-               diff_free_filespec_data(p->two);
-               free(p);
-       }
+       for (i = 0; i < q->nr; i++)
+               diff_free_filepair(q->queue[i]);
        free(q->queue);
        q->queue = NULL;
        q->nr = q->alloc = 0;
index fd11822..c460b2e 100644 (file)
@@ -59,7 +59,7 @@ void diffcore_pathspec(const char **pathspec)
                    matches_pathspec(p->two->path, spec, speccnt))
                        diff_q(&outq, p);
                else
-                       free(p);
+                       diff_free_filepair(p);
        }
        free(q->queue);
        *q = outq;
index fea62d5..4919009 100644 (file)
@@ -49,7 +49,7 @@ void diffcore_pickaxe(const char *needle)
                         contains(p->two, needle, len))
                        diff_q(&outq, p);
                if (onum == outq.nr)
-                       free(p);
+                       diff_free_filepair(p);
        }
        free(q->queue);
        *q = outq;
index 81e4d9d..39a53a8 100644 (file)
@@ -361,11 +361,8 @@ void diffcore_rename(int detect_rename, int minimum_score)
                        else
                                pair_to_free = p;
                }
-               if (pair_to_free) {
-                       diff_free_filespec_data(pair_to_free->one);
-                       diff_free_filespec_data(pair_to_free->two);
-                       free(pair_to_free);
-               }
+               if (pair_to_free)
+                       diff_free_filepair(pair_to_free);
        }
        diff_debug_queue("done copying original", &outq);
 
index ee1955b..0f82bd9 100644 (file)
@@ -54,6 +54,8 @@ struct diff_filepair {
        (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \
        S_ISLNK(mode) ? S_IFLNK : S_IFDIR)
 
+extern void diff_free_filepair(struct diff_filepair *);
+
 extern int diff_unmodified_pair(struct diff_filepair *);
 
 struct diff_queue_struct {