00001 /* -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ 00002 /********************************************************************* 00003 * 00004 * Filename : malloc.h (debug) 00005 * 00006 * This file is a part of the UPPAAL toolkit. 00007 * Copyright (c) 1995 - 2003, Uppsala University and Aalborg University. 00008 * All right reserved. 00009 * 00010 * $Id: malloc.h,v 1.3 2005/07/22 12:55:54 adavid Exp $ 00011 * 00012 *********************************************************************/ 00013 00014 #ifndef INCLUDE_DEBUG_MALLOC_H 00015 #define INCLUDE_DEBUG_MALLOC_H 00016 00017 #include "debug/monitor.h" 00018 00019 #ifdef ENABLE_MONITOR 00020 00021 #ifdef __cplusplus 00022 extern "C" { 00023 #endif 00024 00025 /** @file 00026 * Replace malloc and free by calls to monitored malloc and free 00027 * to check for leaks. The check is automatic because we use g++ 00028 * linker with some internal C++ objects that are automatically 00029 * initialized and destroyed. 00030 * To monitor malloc and free, just add #include "debug/malloc.h" 00031 * to the files where malloc and free are used. 00032 */ 00033 00034 #define malloc(SIZE) debug_monitoredMalloc(SIZE, __FILE__, __LINE__, __FUNCTION__) 00035 #define free(PTR) debug_monitoredFree(PTR, __FILE__, __LINE__, __FUNCTION__) 00036 00037 /** Monitored malloc. 00038 * @return allocated memory, as malloc would do 00039 * @param size: size to allocate, like malloc 00040 * @param filename: filename where malloc is called 00041 * @param line: line where malloc is called 00042 * @param function: function in which malloc is called 00043 */ 00044 void *debug_monitoredMalloc(size_t size, const char *filename, int line, const char *function); 00045 00046 /** Monitored free. 00047 * @param ptr: memory to free 00048 * @param filename: filename where free is called 00049 * @param line: line where free is called 00050 * @param function: function in which free is called 00051 */ 00052 void debug_monitoredFree(void *ptr, const char *filename, int line, const char *function); 00053 00054 #ifdef __cplusplus 00055 } 00056 #endif 00057 00058 #endif /* ENABLE_MONITOR */ 00059 00060 #endif /* INCLUDE_DEBUG_MALLOC_H */