Browse Source

[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>
maint
Junio C Hamano 20 years ago committed by Linus Torvalds
parent
commit
226406f693
  1. 15
      diff.c
  2. 2
      diffcore-pathspec.c
  3. 2
      diffcore-pickaxe.c
  4. 7
      diffcore-rename.c
  5. 2
      diffcore.h

15
diff.c

@ -521,6 +521,13 @@ struct diff_filepair *diff_queue(struct diff_queue_struct *queue,
return dp; 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, static void diff_flush_raw(struct diff_filepair *p,
int line_termination, int line_termination,
int inter_name_termination) int inter_name_termination)
@ -817,12 +824,8 @@ void diff_flush(int diff_output_style, int resolve_rename_copy)
break; break;
} }
} }
for (i = 0; i < q->nr; i++) { for (i = 0; i < q->nr; i++)
struct diff_filepair *p = q->queue[i]; diff_free_filepair(q->queue[i]);
diff_free_filespec_data(p->one);
diff_free_filespec_data(p->two);
free(p);
}
free(q->queue); free(q->queue);
q->queue = NULL; q->queue = NULL;
q->nr = q->alloc = 0; q->nr = q->alloc = 0;

2
diffcore-pathspec.c

@ -59,7 +59,7 @@ void diffcore_pathspec(const char **pathspec)
matches_pathspec(p->two->path, spec, speccnt)) matches_pathspec(p->two->path, spec, speccnt))
diff_q(&outq, p); diff_q(&outq, p);
else else
free(p); diff_free_filepair(p);
} }
free(q->queue); free(q->queue);
*q = outq; *q = outq;

2
diffcore-pickaxe.c

@ -49,7 +49,7 @@ void diffcore_pickaxe(const char *needle)
contains(p->two, needle, len)) contains(p->two, needle, len))
diff_q(&outq, p); diff_q(&outq, p);
if (onum == outq.nr) if (onum == outq.nr)
free(p); diff_free_filepair(p);
} }
free(q->queue); free(q->queue);
*q = outq; *q = outq;

7
diffcore-rename.c

@ -361,11 +361,8 @@ void diffcore_rename(int detect_rename, int minimum_score)
else else
pair_to_free = p; pair_to_free = p;
} }
if (pair_to_free) { if (pair_to_free)
diff_free_filespec_data(pair_to_free->one); diff_free_filepair(pair_to_free);
diff_free_filespec_data(pair_to_free->two);
free(pair_to_free);
}
} }
diff_debug_queue("done copying original", &outq); diff_debug_queue("done copying original", &outq);



2
diffcore.h

@ -54,6 +54,8 @@ struct diff_filepair {
(S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \ (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \
S_ISLNK(mode) ? S_IFLNK : S_IFDIR) S_ISLNK(mode) ? S_IFLNK : S_IFDIR)


extern void diff_free_filepair(struct diff_filepair *);

extern int diff_unmodified_pair(struct diff_filepair *); extern int diff_unmodified_pair(struct diff_filepair *);


struct diff_queue_struct { struct diff_queue_struct {

Loading…
Cancel
Save