about summary refs log tree commit diff homepage
path: root/include
diff options
context:
space:
mode:
authorCristian Cadar <cristic@cs.stanford.edu>2012-04-07 11:37:47 +0000
committerCristian Cadar <cristic@cs.stanford.edu>2012-04-07 11:37:47 +0000
commitdcf55acd75d7a6f74b7b9fa98f84083ea8b79760 (patch)
tree778f48fd84717aea77d3647ca73a25947239a817 /include
parent16c771d54330d73cc66b52922f37a4b6755d04b0 (diff)
downloadklee-dcf55acd75d7a6f74b7b9fa98f84083ea8b79760.tar.gz
Patch by Seungbeom that fixes a memory management issue with Refs, and
associated unit test.  More details at
http://keeda.stanford.edu/pipermail/klee-commits/2012-February/000904.html


git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@154256 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/klee/util/Ref.h29
1 files changed, 14 insertions, 15 deletions
diff --git a/include/klee/util/Ref.h b/include/klee/util/Ref.h
index 1b823f56..d14de471 100644
--- a/include/klee/util/Ref.h
+++ b/include/klee/util/Ref.h
@@ -32,15 +32,15 @@ public:
   ~ref () { dec (); }
 
 private:
-  void inc() {
+  void inc() const {
     if (ptr)
       ++ptr->refCount;
   }
-  
-  void dec() {
+
+  void dec() const {
     if (ptr && --ptr->refCount == 0)
       delete ptr;
-  }  
+  }
 
 public:
   template<class U> friend class ref;
@@ -49,19 +49,18 @@ public:
   ref(T *p) : ptr(p) {
     inc();
   }
-  
+
   // normal copy constructor
   ref(const ref<T> &r) : ptr(r.ptr) {
     inc();
   }
-  
+
   // conversion constructor
   template<class U>
-  ref (const ref<U> &r) {
-    ptr = r.ptr;
+  ref (const ref<U> &r) : ptr(r.ptr) {
     inc();
   }
-  
+
   // pointer operations
   T *get () const {
     return ptr;
@@ -70,18 +69,18 @@ public:
   /* The copy assignment operator must also explicitly be defined,
    * despite a redundant template. */
   ref<T> &operator= (const ref<T> &r) {
+    r.inc();
     dec();
     ptr = r.ptr;
-    inc();
-    
+
     return *this;
   }
-  
+
   template<class U> ref<T> &operator= (const ref<U> &r) {
+    r.inc();
     dec();
     ptr = r.ptr;
-    inc();
-    
+
     return *this;
   }
 
@@ -130,7 +129,7 @@ struct simplify_type<const ::klee::ref<T> > {
   }
 };
 
-template<typename T> 
+template<typename T>
 struct simplify_type< ::klee::ref<T> >
   : public simplify_type<const ::klee::ref<T> > {};
 }