Git development
 help / color / mirror / Atom feed
* [PATCH v2 1/1] Don't free remote->name after fetch
@ 2016-06-14 18:28 kmcguigan
  2016-06-14 18:49 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: kmcguigan @ 2016-06-14 18:28 UTC (permalink / raw)
  To: git; +Cc: Keith McGuigan

From: Keith McGuigan <kmcguigan@twopensource.com>

Make fetch's string_list of remote names owns all of its string items
(strdup'ing when necessary) so that it can deallocate them safely when
clearing.

---
 builtin/fetch.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/builtin/fetch.c b/builtin/fetch.c
index 630ae6a1bb78..1b4e924bd222 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1071,7 +1071,7 @@ static int get_remote_group(const char *key, const char *value, void *priv)
 			size_t wordlen = strcspn(value, " \t\n");
 
 			if (wordlen >= 1)
-				string_list_append(g->list,
+				string_list_append_nodup(g->list,
 						   xstrndup(value, wordlen));
 			value += wordlen + (value[wordlen] != '\0');
 		}
@@ -1261,7 +1261,7 @@ done:
 int cmd_fetch(int argc, const char **argv, const char *prefix)
 {
 	int i;
-	struct string_list list = STRING_LIST_INIT_NODUP;
+	struct string_list list = STRING_LIST_INIT_DUP;
 	struct remote *remote;
 	int result = 0;
 	struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
@@ -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();
-- 
2.8.0.rc3.94.g2dc3105.dirty

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

* Re: [PATCH v2 1/1] Don't free remote->name after fetch
  2016-06-14 18:28 [PATCH v2 1/1] Don't free remote->name after fetch kmcguigan
@ 2016-06-14 18:49 ` Junio C Hamano
  2016-06-14 18:54   ` Keith McGuigan
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2016-06-14 18:49 UTC (permalink / raw)
  To: kmcguigan; +Cc: git

kmcguigan@twopensource.com writes:

> From: Keith McGuigan <kmcguigan@twopensource.com>
>
> Make fetch's string_list of remote names owns all of its string items
> (strdup'ing when necessary) so that it can deallocate them safely when
> clearing.
>
> ---

OK.

When I pointed out the call to string_list_append() in
get_remote_group() as one example, I did not check if there are
others that need similar adjustment.  I just skimmed through the
file again and it seems there is none, so this change looks good.

I assume you meant to sign this off, too?

>  builtin/fetch.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 630ae6a1bb78..1b4e924bd222 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -1071,7 +1071,7 @@ static int get_remote_group(const char *key, const char *value, void *priv)
>  			size_t wordlen = strcspn(value, " \t\n");
>  
>  			if (wordlen >= 1)
> -				string_list_append(g->list,
> +				string_list_append_nodup(g->list,
>  						   xstrndup(value, wordlen));
>  			value += wordlen + (value[wordlen] != '\0');
>  		}
> @@ -1261,7 +1261,7 @@ done:
>  int cmd_fetch(int argc, const char **argv, const char *prefix)
>  {
>  	int i;
> -	struct string_list list = STRING_LIST_INIT_NODUP;
> +	struct string_list list = STRING_LIST_INIT_DUP;
>  	struct remote *remote;
>  	int result = 0;
>  	struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
> @@ -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();

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

* Re: [PATCH v2 1/1] Don't free remote->name after fetch
  2016-06-14 18:49 ` Junio C Hamano
@ 2016-06-14 18:54   ` Keith McGuigan
  2016-06-14 18:57     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Keith McGuigan @ 2016-06-14 18:54 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Yeah that was the only place I found where it was doing the strdup
already (and in that situation, it has to).  All the other places just
grabbed remote->name.

Yes, sorry, I can sign off on this.  Do you want me to resend with the
header in place, or is this confirmation good enough?

--
- Keith

On Tue, Jun 14, 2016 at 2:49 PM, Junio C Hamano <gitster@pobox.com> wrote:
> kmcguigan@twopensource.com writes:
>
>> From: Keith McGuigan <kmcguigan@twopensource.com>
>>
>> Make fetch's string_list of remote names owns all of its string items
>> (strdup'ing when necessary) so that it can deallocate them safely when
>> clearing.
>>
>> ---
>
> OK.
>
> When I pointed out the call to string_list_append() in
> get_remote_group() as one example, I did not check if there are
> others that need similar adjustment.  I just skimmed through the
> file again and it seems there is none, so this change looks good.
>
> I assume you meant to sign this off, too?
>
>>  builtin/fetch.c | 6 ++----
>>  1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/builtin/fetch.c b/builtin/fetch.c
>> index 630ae6a1bb78..1b4e924bd222 100644
>> --- a/builtin/fetch.c
>> +++ b/builtin/fetch.c
>> @@ -1071,7 +1071,7 @@ static int get_remote_group(const char *key, const char *value, void *priv)
>>                       size_t wordlen = strcspn(value, " \t\n");
>>
>>                       if (wordlen >= 1)
>> -                             string_list_append(g->list,
>> +                             string_list_append_nodup(g->list,
>>                                                  xstrndup(value, wordlen));
>>                       value += wordlen + (value[wordlen] != '\0');
>>               }
>> @@ -1261,7 +1261,7 @@ done:
>>  int cmd_fetch(int argc, const char **argv, const char *prefix)
>>  {
>>       int i;
>> -     struct string_list list = STRING_LIST_INIT_NODUP;
>> +     struct string_list list = STRING_LIST_INIT_DUP;
>>       struct remote *remote;
>>       int result = 0;
>>       struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
>> @@ -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();

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

* Re: [PATCH v2 1/1] Don't free remote->name after fetch
  2016-06-14 18:54   ` Keith McGuigan
@ 2016-06-14 18:57     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2016-06-14 18:57 UTC (permalink / raw)
  To: Keith McGuigan; +Cc: git

Keith McGuigan <kmcguigan@twopensource.com> writes:

> Yeah that was the only place I found where it was doing the strdup
> already (and in that situation, it has to).  All the other places just
> grabbed remote->name.
>
> Yes, sorry, I can sign off on this.  Do you want me to resend with the
> header in place, or is this confirmation good enough?

The latter ;-)  Thanks.

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

end of thread, other threads:[~2016-06-14 18:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-14 18:28 [PATCH v2 1/1] Don't free remote->name after fetch kmcguigan
2016-06-14 18:49 ` Junio C Hamano
2016-06-14 18:54   ` Keith McGuigan
2016-06-14 18:57     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox