Skip to content

LLM inference in C/C++

C++ ggml

rpc : invalidate cached compute graph when a referenced buffer is freed (#24292)

y19860199339bcff
diff --git a/ggml/src/ggml-rpc/ggml-rpc.cpp b/ggml/src/ggml-rpc/ggml-rpc.cpp
index adb88a2456..c24caad77e 100644
--- a/ggml/src/ggml-rpc/ggml-rpc.cpp
+++ b/ggml/src/ggml-rpc/ggml-rpc.cpp
@@ -1301,6 +1301,11 @@ bool rpc_server::free_buffer(const rpc_msg_free_buffer_req & request) {
GGML_LOG_ERROR("[%s] buffer not found\n", __func__);
return false;
}
+ // Discard all cached graphs to avoid use-after-free in graph_recompute,
+ // since their nodes may hold pointers to the buffer being freed.
+ for (auto & sg : stored_graphs) {
+ sg.graph = nullptr;
+ }
ggml_backend_buffer_free(buffer);
buffers.erase(buffer);
return true;
@@ -1752,7 +1757,6 @@ bool rpc_server::graph_compute(const std::vector<uint8_t> & input) {
int64_t id;
memcpy(&id, &nodes[i], sizeof(id));
graph->nodes[i] = create_node(id, ctx, tensor_ptrs, tensor_map);
-
// Check if create_node failed for a *non-zero* ID.
// If id was 0, create_node returning nullptr is expected.
// If id was non-zero and create_node returned nullptr, it indicates a deserialization error.