Having some trouble deleting a dynamically allocated array, and I'm not 100% sure why. The only thing I do to this array is copy over some values from it individually (in a for loop), in another routine, which is verified to work correctly.
Here is the declaration in class:
std::complex<float> * frameData;
instantiation in constructor:
this->frameData = new std::complex<float>[n];
srand( time(NULL) );
std::complex<float> randUnityRoot;
for( int i = 0; i < this->n; i++){
randUnityRoot = std::polar(1.0, 2*M_PI * (rand() % 1000000)/1e06);
this->frameData[i] = randUnityRoot;
}
deletion in destructor(this is the line 70 mentioned in the backtrace):
delete[] this->frameData;
gdb backtrace after segfault at program completion:
(gdb) f 4
#4 0x00007ffff7bc579c in Frame::~Frame (this=0x602940,
__in_chrg=<optimized out>) at Frame.cpp:70
70 delete[] this->frameData;
(gdb) f 3
#3 0x00007ffff7669b96 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) f 2
#2 0x00007ffff765f39e in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) f 1
#1 0x00007ffff7624b8b in abort () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) f 0
#0 0x00007ffff7621425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb)
I've been staring at this for a while and am right out of ideas. I figured I would turn to the hive mind. Please let me know if you would like any more information. Thanks!
EDIT: I updated everything to a vector and vector* based approach.
No segfaults :).
To generate some sort of "knowledge gained" from this however, in another class I had called something like:
std::complex<float> * frameGet;
frameGet = this->Frame->getFrame();
// Do stuff with frameGet
//THIS NEXT LINE IS THE BAD PART
delete[] frameGet;
Half question, half assertion: delete[] frameGet calls delete on original array content? If frameGet needs to be deleted should do something like:
frameGet = NULL;
delete frameGet;