From: Junio C Hamano <gitster@pobox.com>
To: kmcguigan@twopensource.com
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/1] Don't free remote->name after fetch
Date: Mon, 13 Jun 2016 15:25:39 -0700 [thread overview]
Message-ID: <xmqqbn34buak.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1465841837-31604-1-git-send-email-kmcguigan@twopensource.com> (kmcguigan@twopensource.com's message of "Mon, 13 Jun 2016 14:17:17 -0400")
kmcguigan@twopensource.com writes:
> From: Keith McGuigan <kmcguigan@twopensource.com>
>
> The string_list gets populated with the names from the remotes[] array,
> which are not dup'd and the list does not own.
>
> Signed-of-by: Keith McGuigan <kmcguigan@twopensource.com>
> ---
For names that come from remote_get()->name, e.g.
static int get_one_remote_for_fetch(struct remote *remote, void *priv)
{
struct string_list *list = priv;
if (!remote->skip_default_update)
string_list_append(list, remote->name);
return 0;
}
you are correct that this is borrowed memory we are not allowed to
free. But is borrowing from remote->name the only way this list is
populated? For example, what happens in add_remote_or_group(),
which does this?
struct remote_group_data {
const char *name;
struct string_list *list;
};
static int get_remote_group(const char *key, const char *value, void *priv)
{
struct remote_group_data *g = priv;
if (skip_prefix(key, "remotes.", &key) && !strcmp(key, g->name)) {
/* split list by white space */
while (*value) {
size_t wordlen = strcspn(value, " \t\n");
if (wordlen >= 1)
string_list_append(g->list,
xstrndup(value, wordlen));
This newly allocated piece of memory is held by g->list, which was...
value += wordlen + (value[wordlen] != '\0');
}
}
return 0;
}
static int add_remote_or_group(const char *name, struct string_list *list)
{
int prev_nr = list->nr;
struct remote_group_data g;
g.name = name; g.list = list;
... passed as a callback parameter from here.
git_config(get_remote_group, &g);
if (list->nr == prev_nr) {
struct remote *remote = remote_get(name);
if (!remote_is_configured(remote))
return 0;
string_list_append(list, remote->name);
This makes remote->name borrowed, which we cannot free() as you
point out.
}
return 1;
}
So, while I agree that many should not be freed, this change makes
the code leak some at the same time.
> builtin/fetch.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 630ae6a1bb78..181da5a2e7a3 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -1347,8 +1347,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
> argv_array_clear(&options);
> }
>
> - /* All names were strdup()ed or strndup()ed */
> - list.strdup_strings = 1;
> string_list_clear(&list, 0);
>
> close_all_packs();
next prev parent reply other threads:[~2016-06-13 22:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-13 18:17 [PATCH 1/1] Don't free remote->name after fetch kmcguigan
2016-06-13 22:25 ` Junio C Hamano [this message]
[not found] ` <CALnYDJO=_hfcQf+=+XuHQwmH4XewqHo4qggzB0rM79WVt+e6nQ@mail.gmail.com>
2016-06-14 0:14 ` Keith McGuigan
2016-06-14 7:52 ` Jeff King
2016-06-14 17:52 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbn34buak.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=kmcguigan@twopensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).