Skip to content

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

@olikraus

Description

@olikraus
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions