summaryrefslogtreecommitdiffstats
path: root/auto_free.h
diff options
context:
space:
mode:
authorTim Moore <moore@blackbox.bricoworks.com>2008-06-29 23:04:31 +0200
committerTim Moore <moore@blackbox.bricoworks.com>2008-06-29 23:53:14 +0200
commit558982c5ade8ae35156d8e6d05e117d49bfa6d45 (patch)
tree888a5004de5c0598d46e819faca75532585bef6e /auto_free.h
parentcfa2ca3cbf2da7bbabcdf35c3085a969bd2370e4 (diff)
downloadsystemtap-steved-558982c5ade8ae35156d8e6d05e117d49bfa6d45.tar.gz
systemtap-steved-558982c5ade8ae35156d8e6d05e117d49bfa6d45.tar.xz
systemtap-steved-558982c5ade8ae35156d8e6d05e117d49bfa6d45.zip
Add auto_free_ref to auto_free stuff; bug 6694
Also add auto_free.h to EXTRA_DIST.
Diffstat (limited to 'auto_free.h')
-rw-r--r--auto_free.h28
1 files changed, 23 insertions, 5 deletions
diff --git a/auto_free.h b/auto_free.h
index b13e7371..58290821 100644
--- a/auto_free.h
+++ b/auto_free.h
@@ -27,14 +27,32 @@ public:
}
private:
// No copying allowed.
- auto_free(const auto_free& af)
+ auto_free(const auto_free& af);
+ // No assignment either
+ auto_free& operator=(const auto_free& rhs);
+ void* _ptr;
+};
+
+// Use this to free a pointer whose value may change after the initial
+// allocation e.g., be realloced.
+template <typename T>
+class auto_free_ref
+{
+public:
+ typedef T pointer_type;
+ auto_free_ref(pointer_type& ptr) : _ptr(ptr)
{
}
- // No assignment either
- auto_free& operator=(const auto_free& rhs)
+ ~auto_free_ref()
{
- return *this;
+ if (_ptr)
+ std::free(_ptr);
}
- void* _ptr;
+private:
+ // No copying allowed.
+ auto_free_ref(const auto_free_ref& af);
+ // No assignment either
+ auto_free_ref& operator=(const auto_free_ref& rhs);
+ pointer_type& _ptr;
};
#endif