+ 1

Why output is double free or corruption out aborted?

here initially 4 nodes and n=node to be deleted =2;prec=precedure node https://code.sololearn.com/c2AEiLsABayN/?ref=app

21st Sep 2018, 7:45 AM
Muppu Supriya
Muppu Supriya - avatar
4 Antworten
+ 1
I had the same problem and problem causes because you copy temp pointer to prec and when you delete temp you are deleting prec too.
21st Sep 2018, 7:49 AM
Alireza Ghazavi
Alireza Ghazavi - avatar
+ 1
how should I overcome this problem then??
21st Sep 2018, 7:50 AM
Muppu Supriya
Muppu Supriya - avatar
+ 1
Yes. In this code you aren't allocing new memory so you are deleting the last memory you were alloced to overcome this problem you should alloc new memory and copy content of last allocing and delete that.
21st Sep 2018, 7:54 AM
Alireza Ghazavi
Alireza Ghazavi - avatar
+ 1
I have corrected it it is delete (*temp)
28th Sep 2018, 8:59 PM
Muppu Supriya
Muppu Supriya - avatar