why Sigabrt error in my code

#include
#include
#include
using namespace std;

int main()
{
int t;
cin>>t;
while(t–)
{
int n,k,power=0;
cin>>n>>k;
string str;
cin.ignore();
getline(cin,str);

char *prev = new char[k];
str.copy(prev,k,0);
char *curr = new char[k];
for(int i=1;i<n-k+1;i++)
{
int count=0;
str.copy(curr,k,i);
for(int j=0;j<k;j++)
{
if(prev[j] != curr[j])
count++;
}
power += count;
strcpy(prev,curr);
}
cout<<power<<endl;
delete [] prev;
delete [] curr;
}
return 0;
}

what’s the problem with my code???. when i running submit this code then in both subtasks gives it sigabrt error. but when i remove this two(delete [] prev , delete [] curr) lines, and submit this code . subtask1 gives Ac, but subtask2 gives sigabrt error.