Thursday, May 23, 2019

debugging - Why do I get: double free or corruption (top) after running this c++ script?

I've got the following piece of code:



Class Chain


with



char* c; 



as its only public atrib



istream& operator>>(istream& i, Chain& s) {
delete [] s.c;
const int L = 256;
char *t = new char[L];
i.getline(t,L);
s.c = t;

return i;
}

ostream& operator<<(ostream& o, Chain s) {
o << s.c;
return o;
}

#include
#include "Chain.h"

using namespace std;

int main(){

Chain id;

cin >> id;

cout << id;
cout << id;



After running the code under the Eclipse IDE on Xubuntu (last version) I get the following error:




Error in [...] double free or corruption (top): 0x00000000008fd290 ***




What could be wrong?

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...