git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/6] userdiff: add xdiff_clear_find_func()

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Jul 1, 2009, 22:01 UTC
Message-ID
<4A4BDCC7.1090405@lsrfire.ath.cx>
In-Reply-To
<4A4BDC65.80504@lsrfire.ath.cx>

xdiff_set_find_func() is used to set user defined regular expressions for finding function signatures. Add xdiff_clear_find_func(), which frees the memory allocated by the former, making the API complete.

Also, use the new function in diff.c (the only call site of xdiff_set_find_func()) to clean up after ourselves.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 diff.c            |    1 +
 xdiff-interface.c |   15 +++++++++++++++
 xdiff-interface.h |    1 +
 3 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/diff.c b/diff.c
index 43835d7..892921c 100644
--- a/diff.c
+++ b/diff.c
@@ -1603,6 +1603,7 @@ static void builtin_diff(const char *name_a,
 			free(mf1.ptr);
 		if (textconv_two)
 			free(mf2.ptr);
+		xdiff_clear_find_func(&xecfg);
 	}
 
  free_ab_and_return:
diff --git a/xdiff-interface.c b/xdiff-interface.c
index b9b0db8..01f14fb 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -309,6 +309,21 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value, int cflags)
 	}
 }
 
+void xdiff_clear_find_func(xdemitconf_t *xecfg)
+{
+	if (xecfg->find_func) {
+		int i;
+		struct ff_regs *regs = xecfg->find_func_priv;
+
+		for (i = 0; i < regs->nr; i++)
+			regfree(&regs->array[i].re);
+		free(regs->array);
+		free(regs);
+		xecfg->find_func = NULL;
+		xecfg->find_func_priv = NULL;
+	}
+}
+
 int git_xmerge_style = -1;
 
 int git_xmerge_config(const char *var, const char *value, void *cb)
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 7352b9a..55572c3 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -21,6 +21,7 @@ int read_mmfile(mmfile_t *ptr, const char *filename);
 int buffer_is_binary(const char *ptr, unsigned long size);
 
 extern void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);
+extern void xdiff_clear_find_func(xdemitconf_t *xecfg);
 extern int git_xmerge_config(const char *var, const char *value, void *cb);
 extern int git_xmerge_style;
 
-- 
1.6.3.3
Previous: René ScharfeNext: René Scharfe
Message 2 of 15 in “grep: add option -p/--show-function, similar to diff's”
  1. 0/6 grep: add option -p/--show-function, similar to diff'sRené Scharfe, Jul 1, 2009
  2. 1/6 userdiff: add xdiff_clear_find_func()René Scharfe, Jul 1, 2009
  3. 2/6 grep: move context hunk mark handling into show_line()René Scharfe, Jul 1, 2009
  4. Junio C HamanoJul 1, 2009
  5. René ScharfeJul 2, 2009
  6. Junio C HamanoJul 2, 2009
  7. 3/6 grep: print context hunk marks between filesRené Scharfe, Jul 1, 2009
  8. 4/6 grep: handle pre context lines on demandRené Scharfe, Jul 1, 2009
  9. 5/6 grep: add option -p/--show-functionRené Scharfe, Jul 1, 2009
  10. Junio C HamanoJul 2, 2009
  11. René ScharfeJul 2, 2009
  12. Junio C HamanoJul 2, 2009
  13. René ScharfeJul 2, 2009
  14. René ScharfeJul 2, 2009
  15. 6/6 grep -p: support user defined regular expressionsRené Scharfe, Jul 1, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.