From dcf55acd75d7a6f74b7b9fa98f84083ea8b79760 Mon Sep 17 00:00:00 2001 From: Cristian Cadar Date: Sat, 7 Apr 2012 11:37:47 +0000 Subject: 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 --- include/klee/util/Ref.h | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'include') 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 friend class ref; @@ -49,19 +49,18 @@ public: ref(T *p) : ptr(p) { inc(); } - + // normal copy constructor ref(const ref &r) : ptr(r.ptr) { inc(); } - + // conversion constructor template - ref (const ref &r) { - ptr = r.ptr; + ref (const ref &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 &operator= (const ref &r) { + r.inc(); dec(); ptr = r.ptr; - inc(); - + return *this; } - + template ref &operator= (const ref &r) { + r.inc(); dec(); ptr = r.ptr; - inc(); - + return *this; } @@ -130,7 +129,7 @@ struct simplify_type > { } }; -template +template struct simplify_type< ::klee::ref > : public simplify_type > {}; } -- cgit 1.4.1