Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members

MemLeak.cpp

Go to the documentation of this file.
00001 /*********************************************************************************
00002  *
00003  * Razor! Engine - A modular C++ presentation engine
00004  *
00005  * $Id$
00006  *
00007  * Copyright (c) 2000 Tilo Christ. All Rights Reserved.
00008  * Adapted from: http://www.fifthgate.org/articles/palm_mem_leaks.html
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  **********************************************************************************/
00025 
00026 
00027 #include <PalmOS.h>
00028 #include "MemLeak.h"
00029 
00030 #if ERROR_CHECK_LEVEL == ERROR_CHECK_FULL
00031 
00032 static const char *LEAK_OUT_NAME = "leaks.txt";
00033 
00034 MemPtr _SafeMemPtrNew(UInt32 size, Char *file, UInt32 line)
00035 {
00036     MemPtr addr = MemPtrNew(size);
00037 
00038     HostFILE *hf = HostFOpen(LEAK_OUT_NAME,"a");
00039     if (hf) 
00040     {
00041         HostFPrintF(hf,"@ 0x%lx 0x%lx %s %ld\n", (UInt32)addr, size, file, line);
00042         HostFClose(hf);
00043     }
00044 
00045     return addr;
00046 }
00047 
00048 Err _SafeMemPtrFree(void *addr, Char *file, UInt32 line)
00049 {
00050     ErrFatalDisplayIf(addr == NULL, "_SafeMemPtrFree: addr == 0!");
00051 
00052     Err error = MemPtrFree(addr);
00053     ErrFatalDisplayIf(error != errNone, "_SafeMemPtrFree: Error!");
00054 
00055 
00056     HostFILE *hf = HostFOpen(LEAK_OUT_NAME,"a");
00057     if (hf) 
00058     {
00059         HostFPrintF(hf,"! 0x%lx %s %ld\n", (UInt32)addr, file, line);
00060         HostFClose(hf);
00061     }
00062 
00063     return error;
00064 }
00065 
00066 
00067 #endif

Razor! Engine Developer's Guide. Copyright © by Tilo Christ. All Rights Reserved. Last updated: 4 Nov 2000