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

[RFH] lifetime rule for url parameter to transport_get()?

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 23, 2011, 00:34 UTC
Message-ID
<7vipppt175.fsf@alter.siamese.dyndns.org>

Does anybody remember why we use a copied string of "ref_git_copy" in builtin/clone.c::setup_reference()?

	ref_git = real_path(option_reference);
	...
	ref_git_copy = xstrdup(ref_git);
	add_to_alternates_file(ref_git_copy);
	remote = remote_get(ref_git_copy);
	transport = transport_get(remote, ref_git_copy);
	for (extra = transport_get_remote_refs(transport); extra;
	     extra = extra->next)
		add_extra_ref(extra->name, extra->old_sha1, 0);
	transport_disconnect(transport);
	free(ref_git_copy);

The three functions add_to_alternates_file(), remote_get(), and transport_get() all get "const char *" so I do not think the copy was done to avoid "option_reference" from getting clobbered by these functions. The only thing I can think of is that transport_get() does this:

    struct transport *transport_get(struct remote *remote, const char *url)
    {
            const char *helper;
            struct transport *ret = xcalloc(1, sizeof(*ret));
            ...
            if (!url && remote->url)
                    url = remote->url[0];
            ret->url = url;
	    ...
	    return ret;
    }

holding onto "url" without making a copy for its own use. But then freeing that copy by the caller after calling transport_disconnect() does not make much sense to me---we could have just gave it the original option_reference, have transport use it while it runs ls-remote equivalent, and then called transport_disconnect(), without using any extra copy.

What I am missing?
Next: Junio C Hamano
Message 1 of 3 in “[RFH] lifetime rule for url parameter to transport_get()?”
  1. Junio C HamanoAug 23, 2011
  2. Junio C HamanoAug 23, 2011
  3. Daniel BarkalowAug 23, 2011

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.