auto_free.h - systemtap
Data types defined
Functions defined
Macros defined
Source code
#ifndef AUTO_FREE_H
#define AUTO_FREE_H 1
#include <cstdlib>
class auto_free
{
public:
auto_free(void* ptr) : _ptr(ptr) {}
~auto_free()
{
if (_ptr)
std::free(_ptr);
}
void release()
{
_ptr = 0;
}
private:
auto_free(const auto_free& af);
auto_free& operator=(const auto_free& rhs);
void* _ptr;
};
template <typename T>
class auto_free_ref
{
public:
typedef T pointer_type;
auto_free_ref(pointer_type& ptr) : _ptr(ptr)
{
}
~auto_free_ref()
{
if (_ptr)
std::free(_ptr);
}
private:
auto_free_ref(const auto_free_ref& af);
auto_free_ref& operator=(const auto_free_ref& rhs);
pointer_type& _ptr;
};
#endif