[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
proposal: avoid potential leakage in src/ov-base-mat.h
From: |
CdeMills |
Subject: |
proposal: avoid potential leakage in src/ov-base-mat.h |
Date: |
Fri, 21 Jan 2011 00:12:42 -0800 (PST) |
Hello,
introducing an operator= in octave_base_matrix to avoid potential leakage.
Indeed, the memory pointed by typ and idx_cache should be released before
being assigned another value.
Proposal (patch produced against hg tip)
----------------------
diff -r 258f6b1166f4 src/ov-base-mat.h
--- a/src/ov-base-mat.h Thu Jan 20 15:50:10 2011 +0100
+++ b/src/ov-base-mat.h Fri Jan 21 09:07:08 2011 +0100
@@ -67,6 +67,18 @@
~octave_base_matrix (void) { clear_cached_info (); }
+ octave_base_matrix& operator= (const octave_base_matrix& m)
+ {
+ if (this == &m) return *this;
+ clear_cached_info ();
+ matrix = m.matrix;
+ /* FIXME: comment out those two lines if you don't want cache info
+ to be duplicated */
+ typ = m.typ ? new MatrixType (*m.typ) : 0;
+ idx_cache = m.idx_cache ? new idx_vector (*m.idx_cache) : 0;
+ return *this;
+ }
+
size_t byte_size (void) const { return matrix.byte_size (); }
octave_value squeeze (void) const { return MT (matrix.squeeze ()); }
------------------------
Regards
Pascal
--
View this message in context:
http://octave.1599824.n4.nabble.com/proposal-avoid-potential-leakage-in-src-ov-base-mat-h-tp3229120p3229120.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.
- proposal: avoid potential leakage in src/ov-base-mat.h,
CdeMills <=