Skip to content

Commit 226406f

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] Introduce diff_free_filepair() funcion.
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>
1 parent a00d7d1 commit 226406f

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

diff.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,13 @@ struct diff_filepair *diff_queue(struct diff_queue_struct *queue,
521521
return dp;
522522
}
523523

524+
void diff_free_filepair(struct diff_filepair *p)
525+
{
526+
diff_free_filespec_data(p->one);
527+
diff_free_filespec_data(p->two);
528+
free(p);
529+
}
530+
524531
static void diff_flush_raw(struct diff_filepair *p,
525532
int line_termination,
526533
int inter_name_termination)
@@ -817,12 +824,8 @@ void diff_flush(int diff_output_style, int resolve_rename_copy)
817824
break;
818825
}
819826
}
820-
for (i = 0; i < q->nr; i++) {
821-
struct diff_filepair *p = q->queue[i];
822-
diff_free_filespec_data(p->one);
823-
diff_free_filespec_data(p->two);
824-
free(p);
825-
}
827+
for (i = 0; i < q->nr; i++)
828+
diff_free_filepair(q->queue[i]);
826829
free(q->queue);
827830
q->queue = NULL;
828831
q->nr = q->alloc = 0;

diffcore-pathspec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void diffcore_pathspec(const char **pathspec)
5959
matches_pathspec(p->two->path, spec, speccnt))
6060
diff_q(&outq, p);
6161
else
62-
free(p);
62+
diff_free_filepair(p);
6363
}
6464
free(q->queue);
6565
*q = outq;

diffcore-pickaxe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void diffcore_pickaxe(const char *needle)
4949
contains(p->two, needle, len))
5050
diff_q(&outq, p);
5151
if (onum == outq.nr)
52-
free(p);
52+
diff_free_filepair(p);
5353
}
5454
free(q->queue);
5555
*q = outq;

diffcore-rename.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,8 @@ void diffcore_rename(int detect_rename, int minimum_score)
361361
else
362362
pair_to_free = p;
363363
}
364-
if (pair_to_free) {
365-
diff_free_filespec_data(pair_to_free->one);
366-
diff_free_filespec_data(pair_to_free->two);
367-
free(pair_to_free);
368-
}
364+
if (pair_to_free)
365+
diff_free_filepair(pair_to_free);
369366
}
370367
diff_debug_queue("done copying original", &outq);
371368

diffcore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct diff_filepair {
5454
(S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \
5555
S_ISLNK(mode) ? S_IFLNK : S_IFDIR)
5656

57+
extern void diff_free_filepair(struct diff_filepair *);
58+
5759
extern int diff_unmodified_pair(struct diff_filepair *);
5860

5961
struct diff_queue_struct {

0 commit comments

Comments
 (0)