Skip to content

Pool*Arrays leaks #223

Open
Open

Description

@bruvzg

Pool arrays created in gdscript and passed to gdnative module are leaking. Or am I missing something and pool arrays should be freed manually?

gdnative module code:

void GDNObj::set_data(const PoolByteArray p_data) {

	if (p_data.size() == 0)
		return;

	if (data)
		std::free(data);

	data = std::malloc(p_data.size());
	std::memcpy(data, p_data.read().ptr(), p_data.size());
}

gdscript code:

func _ready():
	var gdn_obj = GDNObj.new()
	var bytes = PoolByteArray([0x41, 0x00, ... , 0x74, 0x00])
	gdb_obj.set_data(bytes)

Results in following error message at exit:

ERROR: cleanup: There are still MemoryPool allocs in use at exit!
   At: core/dvector.cpp:70.

Activity

  1. Ovnuniarchos commented on Jan 3, 2020

    @Ovnuniarchos

    Confirmed in commit 7cbb846. Any PoolArray, even if it's not accessed, will leak as soon as a change is made on any of the PAs (GDS side or GDN side).

  2. Ovnuniarchos commented on Jun 13, 2020

    @Ovnuniarchos

    Still failing in commit 9eceb16 , but only changes made on the GDScript side trigger the leak.

  3. follower commented on Jun 22, 2020

    @follower

    @Ovnuniarchos Do you have a full example code that includes "changes made on the GDScript side"?

    I was encountering the AFAICT original issue which appears to be gone in 9eceb16 (although I didn't try @bruvzg's specific example) so I wondered what was different with what you were observing and if I understood what you meant by "changes made on the GDScript side".

    Related to what I'm trying to summarize here: #417

  4. 2shady4u commented on Jan 6, 2021

    @2shady4u
    Contributor

    @follower I'm still having this issue on the latest master for my SQLite plugin:
    https://github.com/2shady4u/godot-sqlite/tree/feature-add-blobs

    2

    Capture

    So I don't think it's fixed yet? 🤔

  5. Zylann commented on Jan 6, 2021

    @Zylann
    Collaborator

    I tried reproducing it on Windows but was unable to do so. I used a library compiled in debug mode.
    I tested in Godot 3.2.3 stable and some version of Godot 3.2.4 dated from december 2020. Using -v for verbose output, nothing showed up.

    All my code is doing is this:

    func test_pool_byte_array(): # Called from _ready
    	print("BEGIN test_pool_byte_array")
    	var test = CustomReference.new()
    	var data = PoolByteArray([1, 2, 3])
    	test.test_pool_byte_array(data)
    	# data[0] = 42 # Also tried this, no problem
    	print("END test_pool_byte_array")

    C++:

    void CustomReference::test_pool_byte_array(godot::PoolByteArray data) {
    	PoolByteArray::Read r = data.read();
    }

    To properly figure this out, we need an actual minimal reproduction project (MRP), because it's still not clear under which circumstances this problem occurs (if it still occurs).

    FYI there was a PR back in december 2019 which fixed a leak in PoolArrays: #355

  6. added
    bug
    on Jan 6, 2021
  7. Zylann commented on Jan 6, 2021

    @Zylann
    Collaborator

    Update: we found various cases of leaks when some methods of Dictionary and Array are used, like values() or duplicate(). The leak then becomes apparent when they contain either poolarrays or resources (and curiously doesn't otherwise). However, we could not find an issue with PoolArrays yet.

  8. 2shady4u commented on Jan 6, 2021

    @2shady4u
    Contributor

    Seems like my example is faulty as it pertains to having a PoolArray or Resource in an Array and then duplicating it (or Dictionary and values()), as mentioned by @Zylann in the post above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds testing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions