remote-curl: create copy of the service name
Make a copy of the service name being requested instead of relying on the buffer pointed to by the passed in 'const char *' to remain unchanged. Currently, all service names are string constants, but a subsequent patch will introduce service names from external sources. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Mar 15, 2018 at 10:31 UTC
f08a5d42ea0567af12e703948b6859e30129ec1c
1 file changed
+3
-2
remote-curl.c
+3
-2
@@ -165,7 +165,7 @@ static int set_option(const char *name, const char *value)
165
}
166
167
struct discovery {
168
- const char *service;
168
+ char *service;
169
char *buf_alloc;
170
char *buf;
171
size_t len;
@@ -257,6 +257,7 @@ static void free_discovery(struct discovery *d)
257
free(d->shallow.oid);
258
free(d->buf_alloc);
259
free_refs(d->refs);
260
+ free(d->service);
261
free(d);
262
}
263
}
@@ -343,7 +344,7 @@ static struct discovery *discover_refs(const char *service, int for_push)
344
warning(_("redirecting to %s"), url.buf);
345
346
last= xcalloc(1, sizeof(*last_discovery));
346
- last->service = service;
347
+ last->service = xstrdup(service);
348
last->buf_alloc = strbuf_detach(&buffer, &last->len);
349
last->buf = last->buf_alloc;
350