git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] archive: release refname after use
@ 2020-11-14 22:01 René Scharfe
  2020-11-17  0:28 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2020-11-14 22:01 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

parse_treeish_arg() uses dwim_ref() to set refname to a strdup'd string.
Release it after use.  Also remove the const qualifier from the refname
member to signify that ownership of the string is handed to the struct,
leaving cleanup duty with the caller of parse_treeish_arg(), thus
avoiding a cast.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 archive.c | 1 +
 archive.h | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/archive.c b/archive.c
index 3c1541af9e..da89d292c2 100644
--- a/archive.c
+++ b/archive.c
@@ -662,6 +662,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
 	rc = ar->write_archive(ar, &args);

 	string_list_clear_func(&args.extra_files, extra_file_info_clear);
+	free(args.refname);

 	return rc;
 }
diff --git a/archive.h b/archive.h
index 82b226011a..43028ffbf3 100644
--- a/archive.h
+++ b/archive.h
@@ -8,7 +8,7 @@ struct repository;

 struct archiver_args {
 	struct repository *repo;
-	const char *refname;
+	char *refname;
 	const char *prefix;
 	const char *base;
 	size_t baselen;
--
2.29.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] archive: release refname after use
  2020-11-14 22:01 [PATCH] archive: release refname after use René Scharfe
@ 2020-11-17  0:28 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2020-11-17  0:28 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano

On Sat, Nov 14, 2020 at 11:01:04PM +0100, René Scharfe wrote:

> parse_treeish_arg() uses dwim_ref() to set refname to a strdup'd string.
> Release it after use.  Also remove the const qualifier from the refname
> member to signify that ownership of the string is handed to the struct,
> leaving cleanup duty with the caller of parse_treeish_arg(), thus
> avoiding a cast.

Yeah, I looked at the surrounding code and agree that this is the right
thing to do.

I wondered if it might make  sense for the initialization and clearing
of this "archive_args" structure to go in a pair of matched functions,
but it probably isn't worth the trouble. write_archive() is the only
place where we will allocate and deallocate such a struct (the only
reason it is a type at all is to pass the set of values around the
stack).

-Peff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-17  0:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-14 22:01 [PATCH] archive: release refname after use René Scharfe
2020-11-17  0:28 ` Jeff King

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git