Skip to content

server: add null check for context to prevent segfault on init failure#21477

Open
Anirudh171202 wants to merge 1 commit intoggml-org:masterfrom
Anirudh171202:fix-server-null-ctx-segfault
Open

server: add null check for context to prevent segfault on init failure#21477
Anirudh171202 wants to merge 1 commit intoggml-org:masterfrom
Anirudh171202:fix-server-null-ctx-segfault

Conversation

@Anirudh171202
Copy link
Copy Markdown

Overview

Fixes a segfault when llama_context creation fails.
In server-context.cpp::load_model, the return from common_init_from_params is checked for a null model but not a null context. When context creation fails, llama_n_ctx(ctx) dereferences null and crashes.
This adds a null check for ctx matching the existing model check.

Ref: #21450

Reproduction Steps:

On Apple Silicon,

 ./build/bin/llama-server -hf LiquidAI/LFM2.5-1.2B-Instruct-GGUF:Q4_K_M \
  --ctx-size 32768 \
  -ngl 99 \
  -fa auto \
  --cache-type-k q4_0 \
  --cache-type-v q4_0

It segfaulted before. Now it clean exits with an error message.

Also verified --cache-type-k q4_0 --cache-type-v q4_0 still works normally.

Requirements

@Anirudh171202 Anirudh171202 requested a review from a team as a code owner April 5, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants