Sync with 5.4.0
[deliverable/titan.core.git] / common / new.cc
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
8 #include "dbgnew.hh"
9 #include <stddef.h>
10
11 #undef new
12
13 static void *dummy = NULL;
14
15 void *operator new(size_t size) throw ()
16 {
17 return Malloc(size);
18 }
19
20 void *operator new[](size_t size) throw ()
21 {
22 if (size == 0) return &dummy;
23 else return Malloc(size);
24 }
25
26 void operator delete(void *ptr) throw()
27 {
28 Free(ptr);
29 }
30
31 void operator delete[](void *ptr) throw()
32 {
33 if (ptr != (void*)&dummy) Free(ptr);
34 }
35
36 /**************************************************************************/
37
38 #ifdef MEMORY_DEBUG
39
40 // overloads for memory debug
41 void* operator new(size_t size, const char* file, int line)
42 {
43 return Malloc_dbg(file, line, size);
44 }
45
46 void* operator new[](size_t size, const char* file, int line)
47 {
48 if (size == 0) return &dummy;
49 else return Malloc_dbg(file, line, size);
50 }
51
52 int debug_new_counter_t::count = 0; // initial value
53
54 #if defined(__CYGWIN__) || defined(INTERIX)
55
56 extern char**__argv;
57
58 #else
59
60 const char * __argv [] __attribute__((weak)) =
61 {
62 "program"
63 };
64
65 #endif
66
67 const char * debug_new_counter_t::progname = __argv[0];
68
69 debug_new_counter_t::debug_new_counter_t()
70 {
71 ++count;
72 }
73
74 debug_new_counter_t::~debug_new_counter_t()
75 {
76 if (--count == 0) {
77 check_mem_leak(progname);
78 }
79 }
80
81 void debug_new_counter_t::set_program_name(const char * pgn)
82 {
83 progname = pgn;
84 }
85
86 #endif // MEMORY_DEBUG
This page took 0.047462 seconds and 6 git commands to generate.