Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If we do not use smart pointer, we could not sure that there are some unexpected return code or throw unexpected exceptions in the future. And could not prevent memory leak.


Another case, we write many code like this.

Image Added

Create a new block and put it to a vector or reset it to a unique ptr or shared ptr, and the code will call delete during  free_blocks is cleared. This is unsafe, lets look at Block's constructor:

Image Added

At line 63, it create many columns, if it create 10 column and 11th failed. Then exception is thrown. It will not be add to vector and not released. So that it will be memory leak.

1.2 Lock and Unlock

There are many lock and unlock code. Could not make sure that the lock is correctly released. Should use unique lock or lock guard. For example, in following example, the lock is conditionally locked by checking acquire_lock

...