From eb30aed7c69190fd648947d54bbb9ebe53c67715 Mon Sep 17 00:00:00 2001 From: Jon Loeliger Date: Wed, 27 Sep 2006 11:16:10 -0500 Subject: Removed memory leaks from interpolation table uses. Clarified that parse_extra_args()s results in interpolation table entries. Removed a few trailing whitespace occurrences. Signed-off-by: Jon Loeliger Signed-off-by: Junio C Hamano --- interpolate.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'interpolate.c') diff --git a/interpolate.c b/interpolate.c index 4570c123dc..62701d8435 100644 --- a/interpolate.c +++ b/interpolate.c @@ -4,9 +4,35 @@ #include +#include "git-compat-util.h" #include "interpolate.h" +void interp_set_entry(struct interp *table, int slot, char *value) +{ + char *oldval = table[slot].value; + char *newval = value; + + if (oldval) + free(oldval); + + if (value) + newval = xstrdup(value); + + table[slot].value = newval; +} + + +void interp_clear_table(struct interp *table, int ninterps) +{ + int i; + + for (i = 0; i < ninterps; i++) { + interp_set_entry(table, i, NULL); + } +} + + /* * Convert a NUL-terminated string in buffer orig * into the supplied buffer, result, whose length is reslen, -- cgit v1.2.1