Skip to content

A 304 during --update leaks the response's header buffer#808

Merged
xroche merged 8 commits into
masterfrom
fix/update-304-leak-782
Jul 27, 2026
Merged

A 304 during --update leaks the response's header buffer#808
xroche merged 8 commits into
masterfrom
fix/update-304-leak-782

Conversation

@xroche

@xroche xroche commented Jul 27, 2026

Copy link
Copy Markdown
Owner

back_wait() handles a 304 by replacing the response struct with the cache entry, carrying only the socket and keep-alive members across via back_connxfr(). The struct assignment drops the pointers the live response still owned, freeing none of them. Measured on a two-URL mini304 update: 16 KB in 2 objects, the 8 KB header block http_xfread1() allocated, one per unchanged URL. By that point r.adr has been moved into r.headers, so headers is what actually leaks. With --warc-file the two stashed WARC header blocks go with it, another 1 KB per pass.

back_clear_entry() already knew how to tear those down, so the frees move into a helper that both it and the 304 path call, built on the existing deleteaddr().

The test runs the mini304 crawl with LeakSanitizer on, which the sanitized CI job otherwise disables. The fresh first pass is the control: it has no cache entry to read back and is clean either way. Removing either half of the helper puts it back red, the header block on the update pass and the WARC stashes on the archive pass.

Closes #782

xroche and others added 3 commits July 27, 2026 13:49
back_wait() handles a 304 by replacing the response struct with the cache
entry, carrying only the socket and keep-alive members across via
back_connxfr(). The struct assignment drops every owned pointer the live
response still held without freeing any of them: the 8 KB header buffer on
every update, plus the two WARC header stashes when --warc-file is on. An
update over a 10k-page site drops roughly 80 MB in one run.

back_clear_entry() already knew how to tear those down, so the frees move into
a helper that both it and the 304 path call.

The new test runs the two-pass mini304 crawl with LeakSanitizer on, which the
sanitized CI job otherwise disables. The fresh first pass is the control: it
has no cache entry to read back and is clean either way. The update pass
reports 16 KB in 2 objects on master, one per unchanged URL, and nothing with
the fix.

Closes #782

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
xroche and others added 2 commits July 27, 2026 14:23
back_free_response() was reimplementing deleteaddr(), which already frees adr
and headers and NULLs both; call it instead so the two cannot drift.

Test 114 never passed --warc-file, so the warc_free_request() limb ran with
both pointers NULL on every path it exercised and deleting it kept the test
green. A third pass turns the archive on, and it now fails with the 835 and 238
byte stashes when that call goes away.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche xroche changed the title A 304 during --update leaks the whole previous htsblk A 304 during --update leaks the response's header buffer Jul 27, 2026
The Win32/x64 job pins the exact set of tests allowed to skip, so an
all-skipped suite cannot report green. 114_local-update-304-leak needs a
LeakSanitizer build and MSVC has no equivalent, so it skips there and tripped
the gate with fail=0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
xroche and others added 2 commits July 27, 2026 15:47
Resolve the tests/Makefile.am TESTS-tail conflict: keep both 111 and
114 entries in numeric order.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
Resolve the tests/Makefile.am TESTS-tail conflict: keep 110, 111 and
114 in numeric order.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche
xroche merged commit 8c5b208 into master Jul 27, 2026
22 checks passed
@xroche
xroche deleted the fix/update-304-leak-782 branch July 27, 2026 15:24
@xroche
xroche restored the fix/update-304-leak-782 branch July 27, 2026 15:24
@xroche
xroche deleted the fix/update-304-leak-782 branch July 27, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A 304 during --update leaks the whole previous htsblk (8 KB per unchanged URL)

1 participant