I am creating a scripting engine that would execute my own scripting language. The engine does a double pass through the script, the first pass parses the file and builds the data structure and the second executes the script. The error I am getting is when I try to read in a entire line from the file using getline(std::ifstream, std::string). The error happens at run time which returns this
S_Language(5035) malloc: *** error for object 0x1000212a0: pointer being freed was not allocated
What would be causing this error. I don't get how it is saying that a pointer is being freed that was not allocated. I declared my string that i wanted the line from the file to be written too.
Here is my code for parsing in the file. By the way this is not a homework assignment this is practice for a competition I am trying to enter.
void Parser::Parse() {
std::ifstream fin;
fin.open(this->fileName.c_str(), std::ifstream::in);
if(!fin) {
// Error
this->errorString = "There was an error unable to read file!";
this->error = true;
return;
}
std::string programLine;
std::string label = "";
int lineCounter = 0;
bool firstLineLabel = false;
Operation *OP;
std::list<Operation *> *OPlst;
OPlst = new std::list<Operation *>;
while(!fin.eof()) {
// Get the current line of the document
getline(fin, programLine); // error occurrs here
if(!firstLineLabel && this->hasLabel(programLine)) {
this->startLabel = label = this->getLabel(this->positionOfChar('[',programLine)+1,programLine);
firstLineLabel = true;
}
if(firstLineLabel) {
if(this->hasSemiColon(programLine)) {
this->error = true;
std::stringstream sstr;
sstr << "missing semicolon on line #";
sstr << lineCounter;
this->errorString = sstr.str();
break;
} else {
if(this->hasLabel(programLine)) {
// push the label and OPlst onto the map
labelOPMap[label] = *OPlst;
// Create a new Operation List
OPlst = new std::list<Operation *>;
// get the new label
label = this->getLabel(this->positionOfChar('[',programLine),programLine);
// Clip the label off the string
programLine = programLine.substr(this->positionOfChar(']',programLine)+1);
}
// Parse the current line of the document
OP = this->ProcessLine(programLine);
// push the Operation onto the list
OPlst->push_back(OP);
// Push the text input the list
this->ProgramLines.push_back(programLine);
++lineCounter;
}
}
}
}