summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Burke <spraints@gmail.com>2015-09-25 10:16:16 -0400
committerMatt Burke <spraints@gmail.com>2015-09-25 10:16:30 -0400
commitd7375662e7b4c885ea4865403e4db4c130e79198 (patch)
tree6ac415290f2025cb1ac9ef91546eeb4bc2f1232e /src
parentd16c1b978fa3498a8a800d80ef6ed8a1e39ca314 (diff)
downloadlibgit2-d7375662e7b4c885ea4865403e4db4c130e79198.tar.gz
Copy custom_headers insteach of referencing the caller's copy
Diffstat (limited to 'src')
-rw-r--r--src/remote.c2
-rw-r--r--src/transports/http.c8
-rw-r--r--src/transports/smart.c12
-rw-r--r--src/transports/smart.h2
-rw-r--r--src/transports/winhttp.c26
5 files changed, 26 insertions, 24 deletions
diff --git a/src/remote.c b/src/remote.c
index 84b8d590f..2f8ffcb37 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -689,7 +689,7 @@ int set_transport_callbacks(git_transport *t, const git_remote_callbacks *cbs)
static int set_transport_custom_headers(git_transport *t, const git_strarray *custom_headers)
{
- if (!t->set_custom_headers || !custom_headers)
+ if (!t->set_custom_headers)
return 0;
return t->set_custom_headers(t, custom_headers);
diff --git a/src/transports/http.c b/src/transports/http.c
index 73ea05043..e5f2b9f28 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -211,11 +211,9 @@ static int gen_request(
} else
git_buf_puts(buf, "Accept: */*\r\n");
- if (t->owner->custom_headers) {
- for (i = 0; i < t->owner->custom_headers->count; i++) {
- if (t->owner->custom_headers->strings[i])
- git_buf_printf(buf, "%s\r\n", t->owner->custom_headers->strings[i]);
- }
+ for (i = 0; i < t->owner->custom_headers.count; i++) {
+ if (t->owner->custom_headers.strings[i])
+ git_buf_printf(buf, "%s\r\n", t->owner->custom_headers.strings[i]);
}
/* Apply credentials to the request */
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 8c5bc89e8..b0611c35e 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -124,6 +124,12 @@ static int git_smart__set_custom_headers(
transport_smart *t = (transport_smart *)transport;
size_t i;
+ if (t->custom_headers.count)
+ git_strarray_free(&t->custom_headers);
+
+ if (!custom_headers)
+ return 0;
+
for (i = 0; i < custom_headers->count; i++) {
if (is_malformed_http_header(custom_headers->strings[i])) {
giterr_set(GITERR_INVALID, "custom HTTP header '%s' is malformed", custom_headers->strings[i]);
@@ -135,9 +141,7 @@ static int git_smart__set_custom_headers(
}
}
- t->custom_headers = custom_headers;
-
- return 0;
+ return git_strarray_copy(&t->custom_headers, custom_headers);
}
int git_smart__update_heads(transport_smart *t, git_vector *symrefs)
@@ -436,6 +440,8 @@ static void git_smart__free(git_transport *transport)
git_vector_free(refs);
+ git_strarray_free(&t->custom_headers);
+
git__free(t);
}
diff --git a/src/transports/smart.h b/src/transports/smart.h
index 2c87e0200..800466adf 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -139,7 +139,7 @@ typedef struct {
git_transport_message_cb error_cb;
git_transport_certificate_check_cb certificate_check_cb;
void *message_cb_payload;
- const git_strarray *custom_headers;
+ git_strarray custom_headers;
git_smart_subtransport *wrapped;
git_smart_subtransport_stream *current_stream;
transport_smart_caps caps;
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 5b00d9091..b364e906e 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -410,21 +410,19 @@ static int winhttp_stream_connect(winhttp_stream *s)
}
}
- if (t->owner->custom_headers) {
- for (i = 0; i < t->owner->custom_headers->count; i++) {
- if (t->owner->custom_headers->strings[i]) {
- git_buf_clear(&buf);
- git_buf_puts(&buf, t->owner->custom_headers->strings[i]);
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
- giterr_set(GITERR_OS, "Failed to convert custom header to wide characters");
- goto on_error;
- }
+ for (i = 0; i < t->owner->custom_headers.count; i++) {
+ if (t->owner->custom_headers.strings[i]) {
+ git_buf_clear(&buf);
+ git_buf_puts(&buf, t->owner->custom_headers.strings[i]);
+ if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
+ giterr_set(GITERR_OS, "Failed to convert custom header to wide characters");
+ goto on_error;
+ }
- if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L,
- WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) {
- giterr_set(GITERR_OS, "Failed to add a header to the request");
- goto on_error;
- }
+ if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L,
+ WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) {
+ giterr_set(GITERR_OS, "Failed to add a header to the request");
+ goto on_error;
}
}
}