2012-08-06 21:54:27 -04:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2015-03-29 20:31:42 -04:00
|
|
|
// Copyright (C) 2011-2015 Marianne Gagnon, Joerg Henrichs
|
2012-08-06 21:54:27 -04:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
2013-05-30 15:47:39 -04:00
|
|
|
//
|
2012-08-06 21:54:27 -04:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2013-05-30 15:47:39 -04:00
|
|
|
//
|
2012-08-06 21:54:27 -04:00
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-09-22 14:08:04 -04:00
|
|
|
|
|
|
|
|
2012-08-06 21:54:27 -04:00
|
|
|
#ifndef HEADER_LEAK_CHECK_HPP
|
|
|
|
#define HEADER_LEAK_CHECK_HPP
|
2011-09-22 14:08:04 -04:00
|
|
|
|
2011-10-13 18:55:53 -04:00
|
|
|
|
2013-04-13 10:31:20 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
2014-04-10 18:00:10 -04:00
|
|
|
#include "utils/log.hpp"
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
# include <string>
|
|
|
|
# include <vector>
|
|
|
|
#endif
|
|
|
|
|
2011-09-22 14:08:04 -04:00
|
|
|
namespace MemoryLeaks
|
|
|
|
{
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2012-08-06 21:54:27 -04:00
|
|
|
class AllocatedObject
|
|
|
|
{
|
2014-04-10 18:00:10 -04:00
|
|
|
#if defined(__APPLE__)
|
2012-08-06 21:54:27 -04:00
|
|
|
/** Keep stack information if available (OSX only). */
|
|
|
|
char **m_stack;
|
|
|
|
/** Keeps stacksize information if available (OSX only). */
|
|
|
|
int m_stack_size;
|
2016-06-23 04:18:17 -04:00
|
|
|
#elif defined(WIN32) || ENABLE_LIBBFD
|
|
|
|
/** Keep the stack information the way it is returned by windows or
|
|
|
|
* libbfd, a flat string, which will be split when printing it. */
|
2014-04-10 18:00:10 -04:00
|
|
|
std::string m_stack;
|
|
|
|
#endif
|
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
public:
|
2012-08-06 21:54:27 -04:00
|
|
|
AllocatedObject();
|
|
|
|
virtual ~AllocatedObject();
|
|
|
|
virtual void print() const;
|
|
|
|
}; // AllocatedObjects
|
|
|
|
|
|
|
|
// ========================================================================
|
2011-09-22 14:08:04 -04:00
|
|
|
void checkForLeaks();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2012-08-06 21:54:27 -04:00
|
|
|
void addObject(AllocatedObject* obj);
|
|
|
|
void removeObject(AllocatedObject* obj);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
|
2012-08-06 21:54:27 -04:00
|
|
|
} // namespace MemoryLeaks
|
2011-09-22 14:08:04 -04:00
|
|
|
|
2014-04-10 18:00:10 -04:00
|
|
|
#define LEAK_CHECK() \
|
|
|
|
class LeakCheck : public MemoryLeaks::AllocatedObject \
|
|
|
|
{ \
|
|
|
|
public: \
|
|
|
|
virtual void print() const \
|
|
|
|
{ \
|
|
|
|
Log::error("LeakCheck", "Undeleted object at %s : %i", \
|
|
|
|
__FILE__, __LINE__); \
|
|
|
|
AllocatedObject::print(); \
|
|
|
|
} \
|
|
|
|
virtual ~LeakCheck() {} \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
LeakCheck m_leack_check_instance;
|
2011-09-22 14:08:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
#else
|
2014-04-10 18:00:10 -04:00
|
|
|
// No debugging
|
2011-09-22 14:08:04 -04:00
|
|
|
#define LEAK_CHECK()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|