changeset 28899:02f0649f43d7 stable

Avoid deleting objects that live on the stack. * ov.h (~octave_value, make_unique, operator =), idx-vector.h (~idx_vector, operator =), oct-shlib.h (~dynamic_library, operator =): Avoid calling `delete` on objects that are not allocated with `new`. (Code marked as "Bad free" by clang static analyzer.)
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 13 Oct 2020 19:02:46 +0200
parents a2fbb2074436
children f8efd03a553e 66b52ae69d73
files libinterp/octave-value/ov.h liboctave/array/idx-vector.h liboctave/util/oct-shlib.h
diffstat 3 files changed, 9 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov.h	Sat Oct 10 17:58:44 2020 +0200
+++ b/libinterp/octave-value/ov.h	Tue Oct 13 19:02:46 2020 +0200
@@ -329,7 +329,7 @@
     // operator, rep may be a nullptr here.  We should only need to
     // protect the move assignment operator in a similar way.
 
-    if (rep && --rep->count == 0)
+    if (rep && --rep->count == 0 && rep != nil_rep ())
       delete rep;
   }
 
@@ -339,7 +339,7 @@
       {
         octave_base_value *r = rep->unique_clone ();
 
-        if (--rep->count == 0)
+        if (--rep->count == 0 && rep != nil_rep ())
           delete rep;
 
         rep = r;
@@ -355,7 +355,7 @@
       {
         octave_base_value *r = rep->unique_clone ();
 
-        if (--rep->count == 0)
+        if (--rep->count == 0 && rep != nil_rep ())
           delete rep;
 
         rep = r;
@@ -368,7 +368,7 @@
   {
     if (rep != a.rep)
       {
-        if (--rep->count == 0)
+        if (--rep->count == 0 && rep != nil_rep ())
           delete rep;
 
         rep = a.rep;
@@ -386,7 +386,7 @@
 
     if (this != &a)
       {
-        if (rep && --rep->count == 0)
+        if (rep && --rep->count == 0 && rep != nil_rep ())
           delete rep;
 
         rep = a.rep;
--- a/liboctave/array/idx-vector.h	Sat Oct 10 17:58:44 2020 +0200
+++ b/liboctave/array/idx-vector.h	Tue Oct 13 19:02:46 2020 +0200
@@ -536,7 +536,7 @@
 
   ~idx_vector (void)
   {
-    if (--rep->count == 0)
+    if (--rep->count == 0 && rep != nil_rep ())
       delete rep;
   }
 
@@ -544,7 +544,7 @@
   {
     if (this != &a)
       {
-        if (--rep->count == 0)
+        if (--rep->count == 0 && rep != nil_rep ())
           delete rep;
 
         rep = a.rep;
--- a/liboctave/util/oct-shlib.h	Sat Oct 10 17:58:44 2020 +0200
+++ b/liboctave/util/oct-shlib.h	Tue Oct 13 19:02:46 2020 +0200
@@ -129,7 +129,7 @@
 
     ~dynamic_library (void)
     {
-      if (--m_rep->m_count == 0)
+      if (--m_rep->m_count == 0 && m_rep != &s_nil_rep)
         delete m_rep;
     }
 
@@ -143,7 +143,7 @@
     {
       if (m_rep != sl.m_rep)
         {
-          if (--m_rep->m_count == 0)
+          if (--m_rep->m_count == 0 && m_rep != &s_nil_rep)
             delete m_rep;
 
           m_rep = sl.m_rep;