Skip to content

Commit

Permalink
Connect transfer: Plug memleak on error responses
Browse files Browse the repository at this point in the history
Delete the received pbuf even in case we successfully parse the HTTP
response but are unhappy about the headers.

BFW-5551.
  • Loading branch information
vorner authored and danopernis committed Jun 5, 2024
1 parent df1a133 commit dbd0c90
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/transfers/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class Download::Async {
return static_cast<Async *>(arg)->connected();
}

err_t received_resp(pbuf *data, size_t position) {
err_t received_resp(unique_ptr<pbuf, PbufDeleter> data, size_t position) {
assert(phase == Phase::Headers);
assert(holds_alternative<ResponseParser>(phase_payload));
auto &resp = get<ResponseParser>(phase_payload);
Expand Down Expand Up @@ -262,7 +262,7 @@ class Download::Async {
#else
tcp_pcb *c = conn;
conn = nullptr;
httpd_instance()->inject_transfer(c, data, position, &get<Splice>(phase_payload), len);
httpd_instance()->inject_transfer(c, data.release(), position, &get<Splice>(phase_payload), len);
#endif

return ERR_OK;
Expand Down Expand Up @@ -310,7 +310,7 @@ class Download::Async {

if (parser.done) {
// Will free the passed pbuf (now or later when processed)
return received_resp(data.release(), position);
return received_resp(move(data), position);
}

current = current->next;
Expand Down

0 comments on commit dbd0c90

Please sign in to comment.