Hello.

I tried to correct segmentation fault bug and I have found out a very strange thing imho: creating new instance with "new" returns address of already existing object, constructor is called and my old object is overwritten. I didn't delete my old object before. Could someone tell me what I might do wrong?
Thanks.

Recommended Answers

All 4 Replies

Probably because the program has trashed memory before the line with that new statement was executed. Uninitialized pointers, buffer overruns and writing beyond the bounds of arrays are the most common reasons.

Hmm... I use my own linked lists, put the code into infinite loop and it seems there are no memory leaks. Thanks anyway, going to analyze it one more time...

The problems I mentioned are not memory leaks. That is another problem. If you use <vector> or <list> you can avoid rolling your own links and all the problems they inherently have.

At last I made it... I had to do program to accomplish computations with graphs. I tried to use vectors and sets in the beginning but ended with some ugly errors 'cause I was not allowed to use vectors in non-const functions and couldn't create iterators in const functions or smth like that so I declined them. Now I found several sneaky mistakes and everything is fine now :]

By the way about those containers errors I mentioned above, is it some known issue? Just in case.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.