c++ - HEAP CORRUPTION DETECTED: after Normal block (#143) -


great site.. have error in program , happens when free() sturct pointer type.. cant seem understand why .. think has fact pointer declared globally. thank help!

*note "prev","current" , "head" global , allocated in function using malloc();

the code:

    void approve_delete(int* delete_request){     if(*delete_request == 0){         cout<<" there no more delet requests\n";         return;     }     char choice[5];     char ch;      current = head;     prev = head;     while (current->user.id != max_id ){         if(current->user.want_delete == true){             cout<<"name : "<<current->user.name<<" "<<current->user.last_name<<" id:   "<<current->user.id<<endl;             ch=0;             while( ch != 'y' && ch != 'y' && ch != 'n' && ch != 'n') {                 cout<<"approve delete? y/n  or (q)exit\n";                 cin.width(5);                 cin>>choice;                 ch=choice[0];                 switch (ch) {                 case 'y':                 case 'y':                     item* temp = current;                     prev->next = prev-> next->next;                     current=prev->next;                     free(temp);       //here error occur!                      cout<<"in";                     *delete_request -= 1;                     cout<<"student deleted\n";                     break;                 case 'n':                 case 'n':                     break;                 case 'q':                 case 'q':                     return;                 }             }         }         prev = current;         current = current->next;     } } 

the error comes different part of code. after looking @ whole code (i talked him in private), problem caused type mismatch.

'item' struct has 2 boolean members (last members of type bool). function fills struct data using data file. read file, used fscanf(), , got data boolean members reading numerical values using "%d%d". integers occupy more memory booleans, heap got corrupted.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -