[mlpack-git] master: Fix memory misuse. (7f1b9d0)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Fri Jul 10 18:59:51 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/4a97187bbba7ce8a6191b714949dd818ef0f37d2...e5905e62c15d1bcff21e6359b11efcd7ab6d7ca0
>---------------------------------------------------------------
commit 7f1b9d0f960978e65717a617af43b82077d6230c
Author: ryan <ryan at ratml.org>
Date: Tue Apr 21 16:03:25 2015 -0400
Fix memory misuse.
>---------------------------------------------------------------
7f1b9d0f960978e65717a617af43b82077d6230c
src/mlpack/core/arma_extend/Mat_extra_meat.hpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/mlpack/core/arma_extend/Mat_extra_meat.hpp b/src/mlpack/core/arma_extend/Mat_extra_meat.hpp
index 4e2700d..251ccc6 100644
--- a/src/mlpack/core/arma_extend/Mat_extra_meat.hpp
+++ b/src/mlpack/core/arma_extend/Mat_extra_meat.hpp
@@ -6,6 +6,8 @@ void Mat<eT>::serialize(Archive& ar, const unsigned int /* version */)
using boost::serialization::make_nvp;
using boost::serialization::make_array;
+ const uword old_n_elem = n_elem;
+
// This is accurate from Armadillo 3.6.0 onwards.
// We can't use BOOST_SERIALIZATION_NVP() because of the access::rw() call.
ar & make_nvp("n_rows", access::rw(n_rows));
@@ -16,6 +18,9 @@ void Mat<eT>::serialize(Archive& ar, const unsigned int /* version */)
// mem_state will always be 0 on load, so we don't need to save it.
if (Archive::is_loading::value)
{
+ if (mem_state == 0 && mem != NULL && old_n_elem > 0)
+ memory::release(access::rw(mem));
+
access::rw(mem_state) = 0;
// We also need to allocate the memory we're using.
More information about the mlpack-git
mailing list