The goal of this exercise is to understand what are the main issues
when dealing with owning raw pointers and how tools like valgrind
can help identify them.
Build and run, directly and through valgrind, the following small
programs in https://github.com/infn-esc/esc16/blob/gh-pages/hands-on/cpp:
non_owning_pointer.cpp. Uncomment the lines containing calls tofreeordeleteand see what the consequences are at run-timearray_too_small.cppleak.cpp. Comment the allocations and see what the consequences are at run-timedouble_delete.cppmissed_delete.cpp. Uncomment the lines about thetry/catchblock and position them in different places; see what the consequences are at run-time.
Try and fix the problems.
The commands to build and run the programs are:
[studentNM@esc-XY ~]$ cd esc16/hands-on/cpp
[studentNM@esc-XY cpp]$ g++ -o non_owning_pointer non_owning_pointer.cpp
[studentNM@esc-XY cpp]$ ./non_owning_pointer
[studentNM@esc-XY cpp]$ valgrind ./non_owning_pointer
Similarly for the other programs.