Skip to content

Commit 9d1b654

Browse files
authored
bugfix: eliminate use-after-move undefined behavior. (#345)
1 parent 770f483 commit 9d1b654

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

xllm/api_service/chat_service_impl.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ void ChatServiceImpl::process_async_impl(std::shared_ptr<ChatCall> call) {
625625
CHECK(stream_parser != nullptr) << "create StreamOutputParser failed!";
626626
}
627627

628+
auto saved_tools = request_params.tools;
629+
auto saved_streaming = request_params.streaming;
630+
auto saved_request_id = request_params.request_id;
631+
628632
master_->handle_request(
629633
std::move(messages),
630634
std::move(prompt_tokens),
@@ -633,12 +637,12 @@ void ChatServiceImpl::process_async_impl(std::shared_ptr<ChatCall> call) {
633637
[call,
634638
model,
635639
master = master_,
636-
stream = request_params.streaming,
640+
stream = std::move(saved_streaming),
637641
include_usage = include_usage,
638642
first_message_sent = std::unordered_set<size_t>(),
639-
request_id = request_params.request_id,
643+
request_id = std::move(saved_request_id),
640644
created_time = absl::ToUnixSeconds(absl::Now()),
641-
json_tools = request_params.tools,
645+
json_tools = std::move(saved_tools),
642646
tool_call_parser_format = tool_call_parser_format_,
643647
reasoning_parser_format = reasoning_parser_format_,
644648
is_force_reasoning = is_force_reasoning_,
@@ -741,6 +745,9 @@ void MMChatServiceImpl::process_async_impl(std::shared_ptr<MMChatCall> call) {
741745
include_usage = rpc_request.stream_options().include_usage();
742746
}
743747

748+
auto saved_streaming = request_params.streaming;
749+
auto saved_request_id = request_params.request_id;
750+
744751
// schedule the request
745752
master_->handle_request(
746753
std::move(messages),
@@ -749,10 +756,10 @@ void MMChatServiceImpl::process_async_impl(std::shared_ptr<MMChatCall> call) {
749756
[call,
750757
model,
751758
master = master_,
752-
stream = request_params.streaming,
759+
stream = std::move(saved_streaming),
753760
include_usage = include_usage,
754761
first_message_sent = std::unordered_set<size_t>(),
755-
request_id = request_params.request_id,
762+
request_id = std::move(saved_request_id),
756763
created_time = absl::ToUnixSeconds(absl::Now())](
757764
const RequestOutput& req_output) mutable -> bool {
758765
if (req_output.status.has_value()) {

xllm/api_service/completion_service_impl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ void CompletionServiceImpl::process_async_impl(
196196
request_params.decode_address = rpc_request.routing().decode_name();
197197
}
198198

199+
auto saved_streaming = request_params.streaming;
200+
auto saved_request_id = request_params.request_id;
199201
// schedule the request
200202
master_->handle_request(
201203
std::move(rpc_request.prompt()),
@@ -205,9 +207,9 @@ void CompletionServiceImpl::process_async_impl(
205207
[call,
206208
model,
207209
master = master_,
208-
stream = request_params.streaming,
210+
stream = std::move(saved_streaming),
209211
include_usage = include_usage,
210-
request_id = request_params.request_id,
212+
request_id = std::move(saved_request_id),
211213
created_time = absl::ToUnixSeconds(absl::Now())](
212214
const RequestOutput& req_output) -> bool {
213215
if (req_output.status.has_value()) {

xllm/api_service/embedding_service_impl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void EmbeddingServiceImpl::process_async_impl(
9494
// TODO only support input_str for now
9595
auto& input = rpc_request.input();
9696

97+
auto saved_request_id = request_params.request_id;
9798
// schedule the request
9899
master_->handle_request(
99100
std::move(input),
@@ -102,7 +103,7 @@ void EmbeddingServiceImpl::process_async_impl(
102103
call.get(),
103104
[call,
104105
model,
105-
request_id = request_params.request_id,
106+
request_id = std::move(saved_request_id),
106107
created_time = absl::ToUnixSeconds(absl::Now())](
107108
const RequestOutput& req_output) -> bool {
108109
if (req_output.status.has_value()) {

xllm/api_service/image_generation_service_impl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ void ImageGenerationServiceImpl::process_async_impl(
8383
DiTRequestParams request_params(
8484
rpc_request, call->get_x_request_id(), call->get_x_request_time());
8585

86+
auto saved_request_id = request_params.request_id;
8687
// schedule the request
8788
master_->handle_request(
8889
std::move(request_params),
8990
call.get(),
9091
[call,
9192
model,
92-
request_id = request_params.request_id,
93+
request_id = std::move(saved_request_id),
9394
created_time = absl::ToUnixSeconds(absl::Now())](
9495
const DiTRequestOutput& req_output) -> bool {
9596
if (req_output.status.has_value()) {

0 commit comments

Comments
 (0)