{"thread":{"id":"54646","subject":"[PATCH] archive: release refname after use","startedAt":"2020-11-14T22:02:05Z","lastAt":"2020-11-17T00:28:41Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"409967","messageId":"7692d2f3-0a3b-91cd-c454-9725b0a395a7@web.de","threadId":"54646","inReplyTo":null,"subject":"[PATCH] archive: release refname after use","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2020-11-14T22:01:04Z","receivedAt":"2020-11-14T22:02:05Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"parse_treeish_arg() uses dwim_ref() to set refname to a strdup'd string.\nRelease it after use.  Also remove the const qualifier from the refname\nmember to signify that ownership of the string is handed to the struct,\nleaving cleanup duty with the caller of parse_treeish_arg(), thus\navoiding a cast.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n archive.c | 1 +\n archive.h | 2 +-\n 2 files changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/archive.c b/archive.c\nindex 3c1541af9e..da89d292c2 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -662,6 +662,7 @@ int write_archive(int argc, const char **argv, const char *prefix,\n \trc = ar->write_archive(ar, &args);\n\n \tstring_list_clear_func(&args.extra_files, extra_file_info_clear);\n+\tfree(args.refname);\n\n \treturn rc;\n }\ndiff --git a/archive.h b/archive.h\nindex 82b226011a..43028ffbf3 100644\n--- a/archive.h\n+++ b/archive.h\n@@ -8,7 +8,7 @@ struct repository;\n\n struct archiver_args {\n \tstruct repository *repo;\n-\tconst char *refname;\n+\tchar *refname;\n \tconst char *prefix;\n \tconst char *base;\n \tsize_t baselen;\n--\n2.29.2\n"},{"id":"410054","messageId":"20201117002839.GB13516@coredump.intra.peff.net","threadId":"54646","inReplyTo":"7692d2f3-0a3b-91cd-c454-9725b0a395a7@web.de","subject":"Re: [PATCH] archive: release refname after use","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-11-17T00:28:39Z","receivedAt":"2020-11-17T00:28:41Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Nov 14, 2020 at 11:01:04PM +0100, René Scharfe wrote:\n\n> parse_treeish_arg() uses dwim_ref() to set refname to a strdup'd string.\n> Release it after use.  Also remove the const qualifier from the refname\n> member to signify that ownership of the string is handed to the struct,\n> leaving cleanup duty with the caller of parse_treeish_arg(), thus\n> avoiding a cast.\n\nYeah, I looked at the surrounding code and agree that this is the right\nthing to do.\n\nI wondered if it might make  sense for the initialization and clearing\nof this \"archive_args\" structure to go in a pair of matched functions,\nbut it probably isn't worth the trouble. write_archive() is the only\nplace where we will allocate and deallocate such a struct (the only\nreason it is a type at all is to pass the set of values around the\nstack).\n\n-Peff\n"}]}