SuperTuxKart
Loading...
Searching...
No Matches
leak_check.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2011-2015 Marianne Gagnon, Joerg Henrichs
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License along
16// with this program; if not, write to the Free Software Foundation, Inc.,
17// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
20#ifndef HEADER_LEAK_CHECK_HPP
21#define HEADER_LEAK_CHECK_HPP
22
23
24#ifdef DEBUG
25
26#include "utils/log.hpp"
27
28#ifdef WIN32
29# include <string>
30# include <vector>
31#endif
32
33namespace MemoryLeaks
34{
35
36 class AllocatedObject
37 {
38#if defined(__APPLE__)
40 char **m_stack;
42 int m_stack_size;
43#elif defined(WIN32) || ENABLE_LIBBFD
46 std::string m_stack;
47#endif
48
49 public:
50 AllocatedObject();
51 virtual ~AllocatedObject();
52 virtual void print() const;
53 }; // AllocatedObjects
54
55 // ========================================================================
56 void checkForLeaks();
57
58 void addObject(AllocatedObject* obj);
59 void removeObject(AllocatedObject* obj);
60
61
62} // namespace MemoryLeaks
63
64#define LEAK_CHECK() \
65class LeakCheck : public MemoryLeaks::AllocatedObject \
66{ \
67public: \
68 virtual void print() const \
69 { \
70 Log::error("LeakCheck", "Undeleted object at %s : %i", \
71 __FILE__, __LINE__); \
72 AllocatedObject::print(); \
73 } \
74 virtual ~LeakCheck() {} \
75}; \
76 \
77LeakCheck m_leack_check_instance;
78
79
80#else
81// No debugging
82#define LEAK_CHECK()
83#endif
84
85#endif