Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory issue with Map keys and Vector.push_back() #594

Open
olikraus opened this issue Apr 25, 2022 · 0 comments
Open

Memory issue with Map keys and Vector.push_back() #594

olikraus opened this issue Apr 25, 2022 · 0 comments

Comments

@olikraus
Copy link

olikraus commented Apr 25, 2022

  • Compiler Used: gcc
  • Operating System: mingw
  • Architecture (ARM/x86/32bit/64bit/etc): x86
  • Version 6.1.0

Expected Behavior

Vector.push_back should work

Actual Behavior

Vector.push_back may cause a memory leak / memory issue

Minimal Example to Reproduce Behavior

def keys(Map map) 
{ 
  var v = Vector();
  for( i : map )
  {
    v.push_back(i.first());
  }
  return v;
} 

var k = Vector();
if ( true )
{
	var m = ["a":"x", "b":"y", "c":"z"];
	k = keys(m);
}
print(k);  // expected output should be "[a, b, c]", however sometimes it is "[, b, c]" or a crash of chaiscript 

Remember to execute this example more than once! The bug may not always appear. It is like one of five executions on my system.

Not sure, whether this was reported before or is already resolved, but I thought I should just place it here...

v.push_back(clone(i.first()));

will be a workaround.
There are several preconditions: It seems to appear only with the key part of a map entry and also the map needs to be out of the scope (if-body) related tothe print command. I assume that "m" is deleted before the print command, making the key members of the vector invalid.

Well, at the end, I am not sure whether this is feature of a bug, but at least it is unexpected and may cause really wired problems.

@olikraus olikraus changed the title Memory issue with Vector.push_back() Memory issue with Map keys and Vector.push_back() Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant