Skip to content

Commit 97c5f00

Browse files
Fix bug with Lua infallible allocations (#1139)
* if here is wrong, was pointlessly recreating luarunners * add a test that would have caught this mistake
1 parent 202b9e6 commit 97c5f00

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

libs/server/Lua/LuaStateWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ private bool TryExitInfallibleAllocationRegion()
766766

767767
var ret = customAllocator.TryExitInfallibleAllocationRegion();
768768

769-
if (ret)
769+
if (!ret)
770770
{
771771
NeedsDispose = true;
772772
}

test/Garnet.test/LuaScriptRunnerTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,30 @@ public void InternalFunctionsIgnoredInAllowedFunctions()
737737
ClassicAssert.AreEqual("nil", res);
738738
}
739739

740+
[Test]
741+
public void NeedsDisposeCheck()
742+
{
743+
foreach (var mode in Enum.GetValues<LuaMemoryManagementMode>())
744+
{
745+
foreach (var limit in new[] { null, "1m" })
746+
{
747+
if (limit != null && mode == LuaMemoryManagementMode.Native)
748+
{
749+
continue;
750+
}
751+
752+
var opts = new LuaOptions(mode, limit, Timeout.InfiniteTimeSpan, LuaLoggingMode.Silent, []);
753+
754+
using var runner = new LuaRunner(opts, "return 1");
755+
756+
runner.CompileForRunner();
757+
_ = runner.RunForRunner([], []);
758+
759+
ClassicAssert.IsFalse(runner.NeedsDispose);
760+
}
761+
}
762+
}
763+
740764
private sealed class FakeLogger : ILogger, IDisposable
741765
{
742766
private readonly List<string> logs = new();

0 commit comments

Comments
 (0)