From a308e584cae3fa8cee1d739a858a2d780f1de009 Mon Sep 17 00:00:00 2001 From: mtmcp <141645996+mtmcp@users.noreply.github.com> Date: Fri, 27 Mar 2026 05:01:13 -0300 Subject: [PATCH] completion : Fix segfault on model load failure (#21049) --- tools/completion/completion.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/completion/completion.cpp b/tools/completion/completion.cpp index 58d598fcc0..a24482956e 100644 --- a/tools/completion/completion.cpp +++ b/tools/completion/completion.cpp @@ -146,13 +146,19 @@ int main(int argc, char ** argv) { ctx = llama_init->context(); model = llama_init->model(); - smpl = llama_init->sampler(0); if (ctx == NULL) { LOG_ERR("%s: error: unable to create context\n", __func__); return 1; } + if (model == NULL) { + LOG_ERR("%s: error: unable to load model\n", __func__); + return 1; + } + + smpl = llama_init->sampler(0); + llama_memory_t mem = llama_get_memory(ctx); const llama_vocab * vocab = llama_model_get_vocab(model);