Classdesc  3.D29
Realloc.h
1 /*
2  @copyright Russell Standish 2000-2013
3  @author Russell Standish
4  This file is part of Classdesc
5 
6  Open source licensed under the MIT license. See LICENSE for details.
7 */
8 
9 /*
10  Reimplement realloc to be be non memory-leaking version of what the
11  man page says. By redefining Realloc, the user can replace this by
12  a version of their choice.
13 */
14 #include <iostream>
15 #ifndef REALLOC_H
16 #define REALLOC_H
17 #include <cstdlib>
18 namespace classdesc
19 {
20  inline void *realloc(void *x, std::size_t s)
21  {
22  if (s && x)
23  return std::realloc(x,s);
24  else if (s)
25  return std::malloc(s);
26  else
27  std::free(x);
28  return NULL;
29  }
30 }
31 #endif