]> git.ipfire.org Git - thirdparty/git.git/blobdiff - interpolate.c
Removed memory leaks from interpolation table uses.
[thirdparty/git.git] / interpolate.c
index 4570c123dce811bab8a89efe4c3b4a9a977e6c5a..62701d8435e6c113bf683c72a038874ed1acc2de 100644 (file)
@@ -4,9 +4,35 @@
 
 #include <string.h>
 
+#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,