Source-Python-Dev-Team / Source.Python

This plugin aims to use boost::python and create an easily accessible wrapper around the Source Engine API for scripter use.
http://forums.sourcepython.com
GNU General Public License v3.0
164 stars 32 forks source link

Wrapping a Pointer where auto_dealloc is True with another Pointer will cause double free. #492

Open CookStar opened 1 year ago

CookStar commented 1 year ago

Code:

from memory import Pointer
from memory import alloc

def test_pointer():
    ptr = alloc(4)
    Pointer(ptr)

test_pointer()

Output:

free(): double free detected in tcache 2

This also applies to CustomType.

Code:

from memory import alloc
from memory import make_object
from memory.manager import CustomType
from memory.manager import TypeManager

manager = TypeManager()

class Test(CustomType, metaclass=manager):
    _size = 4

def test_customtype():
    ptr = alloc(4)
    make_object(Test, ptr)

test_customtype()

Output:

free(): double free detected in tcache 2