Bash is telling me my pointer being freed was not allocated. I have made a small program that recreates this issue.
#include <iostream>
#include <cstring>
using namespace std;
void display(char* t);
int main()
{
char normArray[1000];
int size;
cout << "Enter tv show: ";
cin.getline(normArray, 1000);
size = strlen(normArray);
char* dynArray = new char[size];
dynArray = normArray;
display(dynArray);
delete[] dynArray;
return 0;
}
void display(char* t)
{
cout << t << endl;
}
As you can see, "char* dynArray = new char[size]" should be allocating dynArray. "delete[] dynArray" should then be freeing that memory. Yet bash tells me that dynArray is not being allocated.
I've tried just doing "delete dynArray", however, bash warns that I should use delete[] since dynArray is being allocated using "new[]", yet then goes on to say I never allocated it. Any help would be greatly appreciated.
dynArray = normArray;means that the pointerdynArraynow points to the buffernormArray, so yourdeletestatement tries to deletenormArray- M.M