From b78044347c77a7c88d1413bfc80731a1e3b0064f Mon Sep 17 00:00:00 2001 From: redthing1 Date: Mon, 18 Sep 2023 20:56:14 -0700 Subject: [PATCH] fix opaque GetState (fixes #176) --- LLama/LLamaContext.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/LLama/LLamaContext.cs b/LLama/LLamaContext.cs index ed1ab522..3177c76b 100644 --- a/LLama/LLamaContext.cs +++ b/LLama/LLamaContext.cs @@ -210,9 +210,13 @@ namespace LLama // Shrink to size memory = Marshal.ReAllocHGlobal(memory, (nint)actualSize); - // Wrap memory in a state and return it + // Wrap memory in a "state" + var state = new State(memory); + + // Set memory to zero, to prevent it being freed in finally block memory = IntPtr.Zero; - return new State(memory); + + return state; } finally {