m) Fix: http1x memory leak (#427)

[Reproduce]
  http_client send GET/POST request with large headers(val_len > 256Bytes) to http_server, like:
    http_client -H quic.test.com -s ${SERVER_ADDR}:${SERVER_PORT} -p "/test/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -o version=h3 -n 1 -r 100 -R 100

Co-authored-by: wangfuyu <ivanfywang@gmail.com>
This commit is contained in:
wangfuyu 2022-10-13 20:34:04 +08:00 committed by GitHub
parent 8391f907f4
commit def7d956d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -527,12 +527,23 @@ h1h_prepare_decode (void *hset, struct lsxpack_header *xhdr, size_t req_space)
if (0 == hwc->hwc_header_buf_nalloc
|| req_space > hwc->hwc_header_buf_nalloc)
{
buf = malloc(req_space);
if (0 == hwc->hwc_header_buf_nalloc)
{
buf = malloc(req_space);
}
else
{
buf = realloc(hwc->hwc_xhdr.buf, req_space);
}
if (!buf)
{
LSQ_DEBUG("cannot allocate %zd bytes", req_space);
LSQ_WARN("cannot %s %zd bytes",
hwc->hwc_header_buf_nalloc ? "reallocate to" : "allocate", req_space);
return NULL;
}
hwc->hwc_xhdr.buf = buf;
hwc->hwc_header_buf_nalloc = req_space;
}
else