]> Cypherpunks repositories - gostls13.git/commit
archive/zip: reduce memory held by Writer.Copy
authorJonathan Amsterdam <jba@google.com>
Sat, 3 Feb 2024 16:48:50 +0000 (11:48 -0500)
committerJonathan Amsterdam <jba@google.com>
Tue, 6 Feb 2024 12:43:52 +0000 (12:43 +0000)
commit6f44cc88f5f94253096ceed16b8e0fdb117cdd06
tree2f29d91947611e9a6889948a843fa3edf6fe58b2
parent6076edc55c548878c261316f3e3294f1f73125a3
archive/zip: reduce memory held by Writer.Copy

Make a copy of the argument File's FileHeader, and pass a pointer
to the copy to CreateRaw.

Passing the pointer directly causes the entire `File` to be referenced
by the receiver. The `File` includes a reference to the `ReaderAt`
underlying the `Reader`, so all its memory, which may be the entire
contents of the archive, is prevented from being garbage-collected.

Also, explain the issue in the doc comment for CreateRaw. We
cannot change its behavior because someone may depend on the
preserving the identity of its argument pointer.

For #65499.

Change-Id: Ieb4963a0ea30539d597547d3511accbd8c6b5c5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/560238
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
src/archive/zip/writer.go