Eneboo - Documentación para desarrolladores
src/hoard/src/ignoreinvalidfree.h
Ir a la documentación de este archivo.
00001 // -*- C++ -*-
00002 
00003 #ifndef _IGNOREINVALIDFREE_H_
00004 #define _IGNOREINVALIDFREE_H_
00005 
00006 #include "hldefines.h"
00007 
00008 namespace Hoard {
00009 
00010 // A class that checks to see if the object to be freed is inside a
00011 // valid superblock. If not, it drops the object on the floor. We do
00012 // this in the name of robustness (turning a segfault or data
00013 // corruption into a potential memory leak) and because on some
00014 // systems, it's impossible to catch the first few allocated objects.
00015 
00016 template <class S>
00017 class IgnoreInvalidFree : public S {
00018 public:
00019   INLINE void free (void * ptr) {
00020     typename S::SuperblockType * s = S::getSuperblock (ptr);
00021     if (!s || (!s->isValidSuperblock())) {
00022       // We encountered an invalid free, so we drop it.
00023       return;
00024     }
00025     S::free (ptr);
00026   }
00027 
00028   INLINE size_t getSize (void * ptr) {
00029     typename S::SuperblockType * s = S::getSuperblock (ptr);
00030     if (!s || (!s->isValidSuperblock())) {
00031       return 0;
00032     }
00033     return S::getSize (ptr);
00034   }
00035 
00036 private:
00037 
00038   // A special value that is placed into deallocated objects.
00039   enum { ALREADY_FREED_VALUE = 0xDeadBeef };
00040 
00041 };
00042 
00043 }
00044 
00045 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'