Monday, September 2, 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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...