It should be clear by now that C++ provides an extensive set of APIs for allocating and deallocating dynamic memory. It should also be clear that whether you are using malloc()/free() or new()/delete(), errors are not only possible but likely in large applications. For example, you might forget to release memory back to the heap:
#include <iostream>int main(){ auto ptr = new int; std::cout << ptr << '\n';}// > g++ -std=c++17 scratchpad.cpp; valgrind ./a.out// ==8627== LEAK SUMMARY:// ==8627== definitely lost: 4 bytes in 1 blocks// ==8627== indirectly lost: 0 bytes in 0 blocks// ==8627== possibly lost: 0 bytes in 0 blocks// ==8627== still reachable: 0 bytes in 0 blocks// ==8627== suppressed: 0 bytes in 0 blocks ...