From 9037b78263a571b81a3ba97f504c67ed6bb781e7 Mon Sep 17 00:00:00 2001 From: Ruben Ortlam Date: Tue, 31 Mar 2026 09:26:33 +0200 Subject: [PATCH] use unique_ptr for llama_context in HF metadata case --- tests/export-graph-ops.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/export-graph-ops.cpp b/tests/export-graph-ops.cpp index 82f674787b..e37855eee6 100644 --- a/tests/export-graph-ops.cpp +++ b/tests/export-graph-ops.cpp @@ -145,6 +145,7 @@ int main(int argc, char ** argv) { llama_context * ctx; common_init_result_ptr init_result; + llama_context_ptr ctx2; llama_model_ptr model; if (params.model.hf_repo.empty()) { @@ -176,7 +177,8 @@ int main(int argc, char ** argv) { } llama_context_params ctx_params = llama_context_default_params(); - ctx = llama_init_from_model(model.get(), ctx_params); + ctx2.reset(llama_init_from_model(model.get(), ctx_params)); + ctx = ctx2.get(); if (!ctx) { LOG_ERR("failed to create llama_context\n"); @@ -220,10 +222,5 @@ int main(int argc, char ** argv) { test.serialize(f); } - if (!params.model.hf_repo.empty()) { - // Context is not owned by common_init_result in this case - llama_free(ctx); - } - return 0; }