From 8c9d953f2cc8853d53abbc5961505eada8ce03ce Mon Sep 17 00:00:00 2001 From: John Boero Date: Mon, 22 Jan 2024 15:49:36 +0000 Subject: [PATCH] Fixed segfault on invalid grammar. --- examples/server/server.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/server/server.cpp b/examples/server/server.cpp index 0462fbd24..e0f9bdd6b 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -932,6 +932,14 @@ struct llama_server_context llama_sampling_free(slot->ctx_sampling); } slot->ctx_sampling = llama_sampling_init(slot->sparams); + + // If we failed to parse grammar and we continue it's a SEGFAULT. + if (slot->ctx_sampling == nullptr) + { + LOG_TEE("unable to continue without context (is your grammar valid or blank?)\n"); + return false; + } + llama_set_rng_seed(ctx, slot->params.seed); slot->command = LOAD_PROMPT;