source: proiecte/swift/trunk/lib/hoard-371/src/ignoreinvalidfree.h @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 1.1 KB
Line 
1// -*- C++ -*-
2
3#ifndef _IGNOREINVALIDFREE_H_
4#define _IGNOREINVALIDFREE_H_
5
6#include "hldefines.h"
7
8namespace Hoard {
9
10// A class that checks to see if the object to be freed is inside a
11// valid superblock. If not, it drops the object on the floor. We do
12// this in the name of robustness (turning a segfault or data
13// corruption into a potential memory leak) and because on some
14// systems, it's impossible to catch the first few allocated objects.
15
16template <class S>
17class IgnoreInvalidFree : public S {
18public:
19  INLINE void free (void * ptr) {
20    typename S::SuperblockType * s = S::getSuperblock (ptr);
21    if (!s || (!s->isValidSuperblock())) {
22      // We encountered an invalid free, so we drop it.
23      return;
24    }
25    S::free (ptr);
26  }
27
28  INLINE size_t getSize (void * ptr) {
29    typename S::SuperblockType * s = S::getSuperblock (ptr);
30    if (!s || (!s->isValidSuperblock())) {
31      return 0;
32    }
33    return S::getSize (ptr);
34  }
35
36private:
37
38  // A special value that is placed into deallocated objects.
39  enum { ALREADY_FREED_VALUE = 0xDeadBeef };
40
41};
42
43};
44
45#endif
Note: See TracBrowser for help on using the repository browser.