From 2e67a43b11d5b44f962f1c6a0ad89d96e5645a44 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Tue, 24 Jun 2008 14:26:52 +0200 Subject: Cleanup in tapsets.cxx --- auto_free.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 auto_free.h (limited to 'auto_free.h') 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 + +// 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 -- cgit