`ggml_init` can fail if no unused context is found. In that case, a NULL-pointer deref will happen later in the code during a call to `ggml_set_on_alloc`.
This fixes it by bailing out if no context is found.
};
*params.ctx = ggml_init(pdata);
+ if (*params.ctx == NULL) {
+ fprintf(stderr, "%s: failed to initialize context\n", __func__);
+ fclose(file);
+ gguf_free(ctx);
+ return NULL;
+ }
struct ggml_context * ctx_data = *params.ctx;