<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/http-push.c, branch v2.47.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.47.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.47.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2024-09-25T17:24:58Z</updated>
<entry>
<title>http-push: clean up local_refs at exit</title>
<updated>2024-09-25T17:24:58Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:12:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=f4c768c639566da07fc063fa9b52607f54ac94ee'/>
<id>urn:sha1:f4c768c639566da07fc063fa9b52607f54ac94ee</id>
<content type='text'>
We allocate a list of ref structs from get_local_heads() but never clean
it up. We should do so before exiting to avoid complaints from the
leak-checker. Note that we have to initialize it to NULL, because
there's one code path that can jump to the cleanup label before we
assign to it.

Fixing this lets us mark t5540 as leak-free.

Curiously building with SANITIZE=leak and gcc does not seem to find this
problem, but switching to clang does. It seems like a fairly obvious
leak, though.

I was curious that the matching remote_refs did not have the same leak.
But that is because we store the list in a global variable, so it's
still reachable after we exit. Arguably we could treat it the same as
future-proofing, but I didn't bother (now that the script is marked
leak-free, anybody moving it to a stack variable will notice).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>http-push: clean up loose request when falling back to packed</title>
<updated>2024-09-25T17:24:58Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:11:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9699327945d16f67f8a20a299d63621a3b1d3cd2'/>
<id>urn:sha1:9699327945d16f67f8a20a299d63621a3b1d3cd2</id>
<content type='text'>
In http-push's finish_request(), if we fail a loose object request we
may fall back to trying a packed request. But if we do so, we leave the
http_loose_object_request in place, leaking it.

We can fix this by always cleaning it up. Note that the obj_req pointer
here (which we'll set to NULL) is a copy of the request-&gt;userData
pointer, which will now point to freed memory. But that's OK. We'll
either release the parent request struct entirely, or we'll convert it
into a packed request, which will overwrite userData itself.

This leak is found by t5540, but it's not quite leak-free yet.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>http-push: clean up objects list</title>
<updated>2024-09-25T17:24:57Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:10:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=92e1eb491a9b8d47d8aa9e903354f7749fc85c4e'/>
<id>urn:sha1:92e1eb491a9b8d47d8aa9e903354f7749fc85c4e</id>
<content type='text'>
In http-push's get_delta(), we generate a list of pending objects by
recursively processing trees and blobs, adding them to a linked list.
And then we iterate over the list, adding a new request for each
element.

But since we iterate using the list head pointer, at the end it is NULL
and all of the actual list structs have been leaked.

We can fix this either by using a separate iterator and then calling
object_list_free(), or by just freeing as we go. I picked the latter,
just because it means we continue to shrink the list as we go, though
I'm not sure it matters in practice (we call add_send_request() in the
loop, but I don't think it ever looks at the global objects list
itself).

This fixes several leaks noticed in t5540.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>http-push: free xml_ctx.cdata after use</title>
<updated>2024-09-25T17:24:57Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:09:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3245a2ade5ee0ff3e5fad7bd96ad0a630c590e82'/>
<id>urn:sha1:3245a2ade5ee0ff3e5fad7bd96ad0a630c590e82</id>
<content type='text'>
When we ask libexpat to parse XML data, we sometimes set xml_cdata as a
CharacterDataHandler callback. This fills in an allocated string in the
xml_ctx struct which we never free, causing a leak.

I won't pretend to understand the purpose of the field, but it looks
like it is used by other callbacks during the parse. At any rate, we
never look at it again after XML_Parse() returns, so we should be OK to
free() it then.

This fixes several leaks triggered by t5540.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>http-push: free remote_ls_ctx.dentry_name</title>
<updated>2024-09-25T17:24:57Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:09:37Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=a1528093babd4c10415ece172235deb287ca7139'/>
<id>urn:sha1:a1528093babd4c10415ece172235deb287ca7139</id>
<content type='text'>
The remote_ls_ctx struct has dentry_name string, which is filled in with
a heap allocation in the handle_remote_ls_ctx() XML callback. After the
XML parse is done in remote_ls(), we should free the string to avoid a
leak.

This fixes several leaks found by running t5540.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>http-push: free transfer_request strbuf</title>
<updated>2024-09-25T17:24:57Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:08:49Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=94c62857808bdd6b5b061284eb9dfd13204bd11a'/>
<id>urn:sha1:94c62857808bdd6b5b061284eb9dfd13204bd11a</id>
<content type='text'>
When we issue a PUT, we initialize and fill a strbuf embedded in the
transfer_request struct. But we never release this buffer, causing a
leak.

We can fix this by adding a strbuf_release() call to release_request().
If we stopped there, then non-PUT requests would try to release a
zero-initialized strbuf. This works OK in practice, but we should try to
follow the strbuf API more closely. So instead, we'll always initialize
the strbuf when we create the transfer_request struct.

That in turn means switching the strbuf_init() call in start_put() to a
simple strbuf_grow().

This leak is triggered in t5540.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>http-push: free transfer_request dest field</title>
<updated>2024-09-25T17:24:57Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:06:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7d3c71ddbf346bb5182d1cbb4610b9b575b34491'/>
<id>urn:sha1:7d3c71ddbf346bb5182d1cbb4610b9b575b34491</id>
<content type='text'>
When we issue a PUT request, we store the destination in the "dest"
field by detaching from a strbuf. But we never free the result, causing
a leak.

We can address this in the release_request() function. But note that we
also need to initialize it to NULL, as most other request types do not
set it at all.

Curiously there are _two_ functions to initialize a transfer_request
struct. Adding the initialization only to add_fetch_request() seems to
be enough for t5540, but I won't pretend to understand why. Rather than
just adding "request-&gt;dest = NULL" in both spots, let's zero the whole
struct. That addresses this problem, as well as any future ones (and it
can't possibly hurt, as by definition we'd be hitting uninitialized
memory previously).

This fixes several leaks noticed by t5540.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>http-push: free curl header lists</title>
<updated>2024-09-25T17:24:56Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:05:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=747a71019c49d41f46f70562102869e947d944ad'/>
<id>urn:sha1:747a71019c49d41f46f70562102869e947d944ad</id>
<content type='text'>
To pass headers to curl, we have to allocate a curl_slist linked list
and then feed it to curl_easy_setopt(). But the header list is not
copied by curl, and must remain valid until we are finished with the
request.

A few spots in http-push get this right, freeing the list after
finishing the request, but many do not. In most cases the fix is simple:
we set up the curl slot, start it, and then use run_active_slot() to
take it to completion. After that, we don't need the headers anymore and
can call curl_slist_free_all().

But one case is trickier: when we do a MOVE request, we start the
request but don't immediately finish it. It's possible we could change
this to be more like the other requests, but I didn't want to get into
risky refactoring of this code. So we need to stick the header list into
the request struct and remember to free it later.

Curiously, the struct already has a headers field for this purpose! It
goes all the way back to 58e60dd203 (Add support for pushing to a remote
repository using HTTP/DAV, 2005-11-02), but it doesn't look like it was
ever used. We can make use of it just by assigning our headers to it,
and there is already code in finish_request() to clean it up.

This fixes several leaks triggered by t5540.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>http-push: free repo-&gt;url string</title>
<updated>2024-09-25T17:24:56Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:04:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=4324c6c0d97ec48be18dfae8f1c1c3fb77d43f45'/>
<id>urn:sha1:4324c6c0d97ec48be18dfae8f1c1c3fb77d43f45</id>
<content type='text'>
Our repo-&gt;url string comes from str_end_url_with_slash(), which always
allocates its output buffer. We should free it before exiting to avoid
triggering the leak-checker.

This can be seen by leak-checking t5540.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>http-push: clear refspecs before exiting</title>
<updated>2024-09-25T17:24:56Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-09-24T22:04:30Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=85430af347a06b66932eec7c935def4558e0610f'/>
<id>urn:sha1:85430af347a06b66932eec7c935def4558e0610f</id>
<content type='text'>
We parse the command-line arguments into a refspec struct, but we never
free them. We should do so before exiting to avoid triggering the
leak-checker.

This triggers in t5540 many times (basically every invocation of
http-push).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
