From a1f81528853ae13fce4dd2c54d24addc3ad8581c Mon Sep 17 00:00:00 2001 From: Eric Bechet <eric.bechet@ulg.ac.be> Date: Thu, 22 Oct 2009 08:47:12 +0000 Subject: [PATCH] fixed memory leak in assignement --- Numeric/fullMatrix.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Numeric/fullMatrix.h b/Numeric/fullMatrix.h index 41509801b7..a96d7326b7 100644 --- a/Numeric/fullMatrix.h +++ b/Numeric/fullMatrix.h @@ -97,8 +97,14 @@ class fullMatrix if(this != &other){ _r = other._r; _c = other._c; - _data = new scalar[_r * _c]; - for(int i = 0; i < _r * _c; ++i) _data[i] = other._data[i]; + if (_data) delete[] _data; + if ((_r==0)||(_c==0)) + _data=0; + else + { + _data = new scalar[_r * _c]; + for(int i = 0; i < _r * _c; ++i) _data[i] = other._data[i]; + } } return *this; } -- GitLab