Skip to content

Commit aa0834a

Browse files
peffgitster
authored andcommitted
http: clean up leak in init_curl_http_auth
When we have a credential to give to curl, we must copy it into a "user:pass" buffer and then hand the buffer to curl. Old versions of curl did not copy the buffer, and we were expected to keep it valid. Newer versions of curl will copy the buffer. Our solution was to use a strbuf and detach it, giving ownership of the resulting buffer to curl. However, this meant that we were leaking the buffer on newer versions of curl, since curl was just copying it and throwing away the string we passed. Furthermore, when we replaced a credential (e.g., because our original one was rejected), we were also leaking on both old and new versions of curl. This got even worse in the last patch, which started replacing the credential (and thus leaking) on every http request. Instead, let's use a static buffer to make the ownership more clear and less leaky. We already keep a static "struct credential", so we are only handling a single credential at a time, anyway. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dfa1725 commit aa0834a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

http.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ static int http_options(const char *var, const char *value, void *cb)
211211
static void init_curl_http_auth(CURL *result)
212212
{
213213
if (http_auth.username) {
214-
struct strbuf up = STRBUF_INIT;
214+
static struct strbuf up = STRBUF_INIT;
215215
credential_fill(&http_auth);
216+
strbuf_reset(&up);
216217
strbuf_addf(&up, "%s:%s",
217218
http_auth.username, http_auth.password);
218-
curl_easy_setopt(result, CURLOPT_USERPWD,
219-
strbuf_detach(&up, NULL));
219+
curl_easy_setopt(result, CURLOPT_USERPWD, up.buf);
220220
}
221221
}
222222

0 commit comments

Comments
 (0)