Skip to content

Heap corruption when using Get/SetUpValue #48

Description

@pkmnfrk

Version: 1.0.9
.NET Framework 4.6.1

I'm not actually sure if this is a KeraLua issue or a Lua issue (or a PEBCAK issue), but my application terminates when I use GetUpValue or SetUpValue.

The program '[176148] Scratch.exe' has exited with code -1073740940 (0xc0000374).

The exit code means heap corruption.

This sample program reproduces it. Just make a new Console application, reference the KeraLua nuget package, and paste the code into Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KeraLua;

namespace Scratch
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var lua = new Lua())
            {
                DoTest(lua);
            }

            Console.ReadKey(true);
        }

        private static void DoTest(Lua lua)
        {
            lua.LoadString("printf(\"Hello: \" .. _ENV.hello)");

            Console.WriteLine("Is Function? {0}", lua.IsFunction(1));

            var env = lua.GetUpValue(-1, 1);

            Console.WriteLine("_ENV = {0} (Null? {1})", env, env == null);
        }
    }
}

It outputs "Is Function? True" before the crash, and doesn't get to the "_ENV" line

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions