Mercurial > octave
changeset 30769:822649f5f193 stable
don't mix operator new and free (bug #61813)
* mex.cc (fp_to_ov<T>): Only allow octave_value to borrow mxArray data
if using std::pmr::polymorphic_allocator.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 21 Feb 2022 12:41:12 -0500 |
parents | 6bc535476d5f |
children | 2aff9dda08f1 |
files | libinterp/corefcn/mex.cc |
diffstat | 1 files changed, 13 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/mex.cc Mon Feb 21 12:34:38 2022 -0500 +++ b/libinterp/corefcn/mex.cc Mon Feb 21 12:41:12 2022 -0500 @@ -2150,32 +2150,19 @@ #else - if (fp_type_traits<ELT_T>::is_complex) - { - // Mixing malloc and delete[] for arrays of Complex and - // FloatComplex objects is not possible. - - Array<ELT_T> val (dv); - - ELT_T *ptr = val.fortran_vec (); - - mwSize nel = get_number_of_elements (); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = ppr[i]; - - return octave_value (val); - } - else - { - // Although behavior is not specified by the standard, it should - // work to mix malloc and delete[] for arrays of float and - // double. - - octave::unwind_action act ([=] () { maybe_disown_ptr (m_pr); }); - - return octave_value (Array<ELT_T> (ppr, dv)); - } + // Copy data instead of allowing the octave_value object to borrow + // the mxArray object data. + + Array<ELT_T> val (dv); + + ELT_T *ptr = val.fortran_vec (); + + mwSize nel = get_number_of_elements (); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = ppr[i]; + + return octave_value (val); #endif }