mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-29 08:41:22 +00:00 
			
		
		
		
	Properly free llama_context on failure
This commit is contained in:
		| @@ -1432,7 +1432,7 @@ struct llama_context * llama_init_from_file( | ||||
|     if (!llama_model_load(path_model, *ctx, params.n_ctx, params.n_parts, type_memory, | ||||
|                           params.vocab_only)) { | ||||
|         fprintf(stderr, "%s: failed to load model\n", __func__); | ||||
|         delete ctx; | ||||
|         llama_free(ctx); | ||||
|         return nullptr; | ||||
|     } | ||||
|  | ||||
| @@ -1441,7 +1441,7 @@ struct llama_context * llama_init_from_file( | ||||
|         if (!ggml_mlock(ctx->model.ctx, &err)) { | ||||
|             fprintf(stderr, "%s\n", err); | ||||
|             free(err); | ||||
|             delete ctx; | ||||
|             llama_free(ctx); | ||||
|             return nullptr; | ||||
|         } | ||||
|     } | ||||
| @@ -1464,7 +1464,9 @@ struct llama_context * llama_init_from_file( | ||||
| } | ||||
|  | ||||
| void llama_free(struct llama_context * ctx) { | ||||
|     if (ctx->model.ctx) { | ||||
|         ggml_free(ctx->model.ctx); | ||||
|     } | ||||
|  | ||||
|     delete ctx; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Georgi Gerganov
					Georgi Gerganov