Skip to content

Commit 06f179d

Browse files
committed
lib/uri: Trim slack past data end after gzip drain to free unused buffer tail
1 parent 88f0d46 commit 06f179d

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

common/lib/uri.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,16 @@ grew:;
497497
buf_len += got;
498498
}
499499

500+
// Release the page-aligned tail past the actual data so we don't
501+
// hand the OS up to 64 MiB of slack typed as `type`. Keep at least
502+
// one page so the returned handle has a valid address.
503+
uint64_t kept = ALIGN_UP(buf_len, 4096, panic(true, "uri: alignment overflow"));
504+
if (kept == 0) kept = 4096;
505+
if (kept < buf_cap) {
506+
uri_release_range(buf_addr + kept, buf_cap - kept);
507+
buf_cap = kept;
508+
}
509+
500510
#if defined (__i386__)
501511
if (pool != NULL) pmm_free(pool, 0x100000);
502512
#endif

0 commit comments

Comments
 (0)