Fix an http use after free during shutdown.

This commit is contained in:
Cory McWilliams 2024-03-25 16:31:09 -04:00
parent 610e756c07
commit 5385264f94

View File

@ -381,12 +381,20 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
};
connection->request = request;
if (!connection->http->is_shutting_down)
{
tf_http_request_ref(request);
tf_trace_begin(connection->http->trace, connection->trace_name ? connection->trace_name : "http");
connection->callback(request);
tf_trace_end(connection->http->trace);
tf_http_request_unref(request);
}
else
{
const char* k_payload = tf_http_status_text(503);
tf_http_respond(request, 503, NULL, 0, k_payload, strlen(k_payload));
}
}
}
}
@ -784,6 +792,8 @@ const char* tf_http_status_text(int status)
return "File not found";
case 500:
return "Internal server error";
case 503:
return "Service Unavailable";
default:
return "Unknown";
}