Mercurial > octave
changeset 28967:bcfa15435e4c stable
avoid possible deletion of static object (bug #59228)
* dim-vector.cc (dim_vector::nil_rep): Directly create and return a
static rep object instead returning a pointer to the rep object
belonging to a static dim_vector object.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Oct 2020 13:27:38 -0400 |
parents | e4f767de937a |
children | 437e04d9c449 a00eca5d6cbe |
files | liboctave/array/dim-vector.cc |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/array/dim-vector.cc Sat Oct 17 14:31:26 2020 +0200 +++ b/liboctave/array/dim-vector.cc Tue Oct 20 13:27:38 2020 -0400 @@ -39,8 +39,16 @@ octave_idx_type * dim_vector::nil_rep (void) { - static dim_vector zv (0, 0); - return zv.rep; + // Create a statically allocated rep object with an initial reference + // count of 1. The dim_vector constructor that uses this object will + // increment the reference count. The dim_vector destructor and copy + // assignment operator will decrement the reference count but those + // operations can never cause the count to become zero so they will + // never call delete on this object. + + static octave_idx_type nr[4] = { 1, 2, 0, 0 }; + + return &nr[2]; } // The maximum allowed value for a dimension extent. This will normally be a