munkres-cpp
munkres-cpp copied to clipboard
Memory leak if bad_alloc happens
Just want to note, that whenever you write code (you usually see this kind of thing in various tutorials) like this
m_matrix = new T*[rows]; // rows
for ( size_t i = 0 ; i < rows ; i++ ) {
m_matrix[i] = new T[columns]; // columns
}
you have a memory leak, because any of the new T[columns]
can throw an exception.
Standard way to fix that is to either use std::unique_ptr
or std::vector
. But even better thing to do here is to use one std::vector
of size columns * rows
, because that will improve cache locality.