summaryrefslogtreecommitdiffstats
path: root/auto_free.h
diff options
context:
space:
mode:
authorTim Moore <moore@blackbox.bricoworks.com>2008-06-24 14:26:52 +0200
committerTim Moore <moore@blackbox.bricoworks.com>2008-06-24 16:23:14 +0200
commit2e67a43b11d5b44f962f1c6a0ad89d96e5645a44 (patch)
tree0e3609367c3c4d0f3d41eb089330a3b25db5c346 /auto_free.h
parent8548f326bbbc5c99d692757618f4a7260b552de9 (diff)
downloadsystemtap-steved-2e67a43b11d5b44f962f1c6a0ad89d96e5645a44.tar.gz
systemtap-steved-2e67a43b11d5b44f962f1c6a0ad89d96e5645a44.tar.xz
systemtap-steved-2e67a43b11d5b44f962f1c6a0ad89d96e5645a44.zip
Cleanup in tapsets.cxx
Diffstat (limited to 'auto_free.h')
-rw-r--r--auto_free.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/auto_free.h b/auto_free.h
new file mode 100644
index 00000000..b13e7371
--- /dev/null
+++ b/auto_free.h
@@ -0,0 +1,40 @@
+// -*- C++ -*-
+// Copyright (C) 2008 Red Hat Inc.
+//
+// This file is part of systemtap, and is free software. You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+
+#ifndef AUTO_FREE_H
+#define AUTO_FREE_H 1
+#include <cstdlib>
+
+// Very simple auto_ptr-like class for protecting storage allocated
+// with free().
+class auto_free
+{
+public:
+ auto_free(void* ptr) : _ptr(ptr) {}
+ ~auto_free()
+ {
+ if (_ptr)
+ std::free(_ptr);
+ }
+ void release()
+ {
+ _ptr = 0;
+ }
+private:
+ // No copying allowed.
+ auto_free(const auto_free& af)
+ {
+ }
+ // No assignment either
+ auto_free& operator=(const auto_free& rhs)
+ {
+ return *this;
+ }
+ void* _ptr;
+};
+#endif