C++ Memory Management is broken | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ Memory Management is broken

I'm messing around with memory management in c++, but I got weird output. It doesn't say its an error or warning, it says free(): double free detected in tcache2. What does it mean? https://code.sololearn.com/coS0bmKqyRJ7/?ref=app

27th Jun 2020, 9:04 PM
Clueless Coder
Clueless Coder - avatar
2 Answers
+ 3
You are doing free and delete on ptr. free(ptr); delete ptr; Please remove one of them.
27th Jun 2020, 9:07 PM
$ยข๐Žโ‚น๐”ญ!๐จ๐“
$ยข๐Žโ‚น๐”ญ!๐จ๐“ - avatar
+ 2
Remove delete ptr; usually delete is used with new. And free with malloc and calloc.
27th Jun 2020, 9:09 PM
$ยข๐Žโ‚น๐”ญ!๐จ๐“
$ยข๐Žโ‚น๐”ญ!๐จ๐“ - avatar