Here is the code. What interests me is new_data. Why delete[] new_data crashes program? How to fix it? There is a lot going on inside functions and anyway I am writing it to post this post as I am getting: "It looks like your post is mostly code; please add some more details." error, so sorry for the spam but I have such problem with a lot of lines of code so SO asks me to describe my problem with many words.
char * new_data;
...
new_data = new char[end_file-beg_file+20000000];
string i_str;
i_str=potential_frames(file_data,end_file-beg_file);
struct frame * f1 = new frame[i_str.size()/4];
for(long n=0;n<i_str.size()/4;n++){
f1[n].i_point=((int)i_str[n*4])*256*256*256+((int)i_str[n*4+1])*256*256+((int)i_str[n*4+2])*256+((int)i_str[n*4+3]);
f1[n].find_frame_param(file_data);
}
frames_stats(f1,i_str.size()/4, file_data,0);
valid_frames=check_frames(f1,i_str.size()/4);
frames_stats(f1,i_str.size()/4, file_data,1);
if(adjust_first_dis_fr+adjust_displayed_frames>i_str.size()/4){
cout<<"adjust_displayed_frames reached over last frame"<<endl;
adjust_displayed_frames=(i_str.size()/4)-adjust_first_dis_fr;
}
//
for(int i=adjust_first_dis_fr;i<adjust_displayed_frames+adjust_first_dis_fr;i++)if(f1[i].valid_frame==1||show_only_valid_frames_sw==0){
cout<<std::dec<<i<<"/"<<f1[i].valid_frame_index<<") ";
cout<<f1[i].i_point+f1[i].flb<<"i+flb ";
f1[i].display_param();
if(show_frame_data_sw)f1[i].display(file_data+f1[i].i_point);
}
for(int i=0; i<file_name.find(".mp3");i++)new_file_name=new_file_name+file_name[i];
new_file_name=new_file_name+"_cleaned.mp3";
ofstream clean (new_file_name, ios::binary);
if(clean.is_open());
else {
cout<<"Couldnt create "<<new_file_name<<endl;
}
s=rewrite_frames(f1, i_str.size()/4, file_data, new_data);
for(int i=0;i<s;i++)clean<<*(new_data+i);
cout<<endl;
cleaned_size=clean.tellp();
clean.close();
cout<<endl;
delete[] f1;
delete[] new_data;
}
else{
cout<<"Uneable to open mp3 file"<<endl;
unopened_mp3_files++;
}
delete[] file_data;
...
delete[] new_data crashes program. Why?