Skip to content

Commit

Permalink
Use references explicitly, and avoid dangling references captured by …
Browse files Browse the repository at this point in the history
…complete_request_handler_
  • Loading branch information
paulharris committed Oct 17, 2024
1 parent 25ca2f5 commit cfbe424
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"

try
{
auto& rule = rules[rule_index];
BaseRule& rule = *rules[rule_index];
handle_rule<App>(rule, req, res, found.r_params);
}
catch (...)
Expand All @@ -1738,13 +1738,13 @@ namespace crow // NOTE: Already documented in "crow/app.h"

template<typename App>
typename std::enable_if<std::tuple_size<typename App::mw_container_t>::value != 0, void>::type
handle_rule(BaseRule* rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
handle_rule(BaseRule& rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
{
if (!rule->mw_indices_.empty())
if (!rule.mw_indices_.empty())
{
auto& ctx = *reinterpret_cast<typename App::context_t*>(req.middleware_context);
auto& container = *reinterpret_cast<typename App::mw_container_t*>(req.middleware_container);
detail::middleware_call_criteria_dynamic<false> crit_fwd(rule->mw_indices_.indices());
detail::middleware_call_criteria_dynamic<false> crit_fwd(rule.mw_indices_.indices());

auto glob_completion_handler = std::move(res.complete_request_handler_);
res.complete_request_handler_ = [] {};
Expand All @@ -1759,7 +1759,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
}

res.complete_request_handler_ = [&rule, &ctx, &container, &req, &res, glob_completion_handler] {
detail::middleware_call_criteria_dynamic<true> crit_bwd(rule->mw_indices_.indices());
detail::middleware_call_criteria_dynamic<true> crit_bwd(rule.mw_indices_.indices());

detail::after_handlers_call_helper<
decltype(crit_bwd),
Expand All @@ -1769,14 +1769,14 @@ namespace crow // NOTE: Already documented in "crow/app.h"
glob_completion_handler();
};
}
rule->handle(req, res, rp);
rule.handle(req, res, rp);
}

template<typename App>
typename std::enable_if<std::tuple_size<typename App::mw_container_t>::value == 0, void>::type
handle_rule(BaseRule* rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
handle_rule(BaseRule& rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
{
rule->handle(req, res, rp);
rule.handle(req, res, rp);
}

void debug_print()
Expand Down

0 comments on commit cfbe424

Please sign in to comment.