[mod_verto] Release POST body and request state on HTTP error paths (#3299)

`http_run()` left the form-urlencoded POST body buffer allocated when
`kws_raw_read()` failed or the peer closed mid-body, up to
`HTTP_POST_MAX_BODY` per connection. Free it there, and clear
`keepalive` so the unread rest of the body is not parsed as the next
request.

The `err:` exit also freed neither `request` nor `stream.param_event`:
a header parse failure leaked the event, and a non-Basic
`Authorization` header leaked both. It now releases both, which makes
`request_err:` redundant, so its two users jump to `err:` instead.
This commit is contained in:
Dmitry Verenitsin authored and GitHub committed 2026-11-18 22:07:00 +03:00
1 parent b5336ca3f9
commit bc63ad6f89
1 file changed
+8 -5
+8 -5
View File
@@ -1868,7 +1868,7 @@ new_req:
}
if (!(buffer = malloc(request->content_length + 1))) {
goto request_err;
goto err;
}
while(bytes < (switch_ssize_t)request->content_length) {
@@ -1878,6 +1878,8 @@ new_req:
if ((len = kws_raw_read(jsock->ws, buffer + bytes, len, WS_BLOCK)) <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read error %" SWITCH_SSIZE_T_FMT"\n", len);
free(buffer);
request->keepalive = 0;
goto done;
}
@@ -1945,7 +1947,7 @@ new_req:
}
if (!(params = cJSON_CreateObject())) {
goto request_err;
goto err;
}
cJSON_AddItemToObject(params, "login", cJSON_CreateString(auth_user));
@@ -2036,13 +2038,14 @@ done:
return;
request_err:
kws_request_free(&request);
err:
err = "HTTP/1.1 500 Internal Server Error\r\n"
"Content-Length: 0\r\n\r\n";
kws_raw_write(jsock->ws, err, strlen(err));
kws_request_free(&request);
if (stream.param_event) {
switch_event_destroy(&stream.param_event);
}
error:
return;