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

Re: [PATCH v8 2/2] test-config: add tests for the config_set API

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jul 11, 2014, 14:24 UTC
Message-ID
<vpqwqbk0y8n.fsf@anie.imag.fr>
In-Reply-To
<1405049655-4265-3-git-send-email-tanayabh@gmail.com>
Tanay Abhra <tanayabh@gmail.com> writes:
Show 5 quoted lines
> diff --git a/test-config.c b/test-config.c
> new file mode 100644
> index 0000000..dc313c2
> --- /dev/null
> +++ b/test-config.c
Show 7 quoted lines
> +int main(int argc, char **argv)
> +{
> +	int i, val;
> +	const char *v;
> +	const struct string_list *strptr;
> +	struct config_set cs;
> +	git_configset_init(&cs);
The configset is initialized, but never cleared.

As a result, valgrind --leak-check=full complains with "definitely lost" items.

I think it would make sense to apply something like this to get a valgrind-clean test-config.c (I checked, it now passes without warnings):

diff --git a/test-config.c b/test-config.c
index dc313c2..07b61ef 100644
--- a/test-config.c
+++ b/test-config.c
@@ -41,17 +41,17 @@ int main(int argc, char **argv)
 
 	if (argc < 2) {
 		fprintf(stderr, "Please, provide a command name on the command-line\n");
-		return 1;
+		goto exit1;
 	} else if (argc == 3 && !strcmp(argv[1], "get_value")) {
 		if (!git_config_get_value(argv[2], &v)) {
 			if (!v)
 				printf("(NULL)\n");
 			else
 				printf("%s\n", v);
-			return 0;
+			goto exit0;

[...]
 
 	fprintf(stderr, "%s: Please check the syntax and the function name\n", argv[0]);
+	goto exit1;
+
+exit0:
+	git_configset_clear(&cs);
+	return 0;
+
+exit1:
+	git_configset_clear(&cs);
 	return 1;
+
+exit2:
+	git_configset_clear(&cs);
+	return 2;
 }

I'll resend as a proper "git am"-able patch right after.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Tanay AbhraNext: Matthieu Moy
Message 10 of 14 in “git config cache & special querying api utilizing the cache”
  1. 0/3 git config cache & special querying api utilizing the cacheTanay Abhra, Jul 11, 2014
  2. 1/2 add `config_set` API for caching config-like filesTanay Abhra, Jul 11, 2014
  3. Matthieu MoyJul 11, 2014
  4. Tanay AbhraJul 11, 2014
  5. Matthieu MoyJul 11, 2014
  6. Tanay AbhraJul 15, 2014
  7. Matthieu MoyJul 15, 2014
  8. Junio C HamanoJul 11, 2014
  9. 2/2 test-config: add tests for the config_set APITanay Abhra, Jul 11, 2014
  10. Matthieu MoyJul 11, 2014
  11. 1/2 Call configset_clearMatthieu Moy, Jul 11, 2014
  12. 2/2 Better tests for error casesMatthieu Moy, Jul 11, 2014
  13. Junio C HamanoJul 11, 2014
  14. Tanay AbhraJul 15, 2014

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.