Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

smalloc.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 /*
00003 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
00004 **
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 **
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 **
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 /*
00021  * Snort frontend to malloc
00022  */
00023 
00024 #ifndef __SMALLOC_H__
00025 #define __SMALLOC_H__
00026 
00027 
00028 #include <stdlib.h>
00029 
00030 #include "debug.h"
00031 
00032 
00033 
00034 /* MALLOC flags */
00035 
00036 #define M_EXIT          1       /* exit if memory allocation fails (default) */
00037 #define M_DONTEXIT      2       /* don't exit if memory allocation fails */
00038 #define M_ZERO          4       /* zero out the allocated memory */
00039 
00040 
00041 #define MALLOC(ptr, cast, size, flags)                                  \
00042 do {                                                                    \
00043         (ptr) = (cast) malloc((size));                                  \
00044         if (!((flags) & M_DONTEXIT) && ((ptr)  == NULL))                \
00045         {                                                               \
00046                 DebugMessage(DEBUG_ALL, "malloc: out of memory (allocating %d bytes)\n", (size));                                                       \
00047                 exit(1);                                                \
00048         }                                                               \
00049         if (((flags) & M_ZERO) && ((ptr) != NULL))                      \
00050                 memset((ptr), '\0', (size));                            \
00051 } while (0)
00052 
00053 
00054 #define FREE(ptr)                                                       \
00055 do {                                                                    \
00056         if ((ptr) == NULL)                                              \
00057         {                                                               \
00058                 DebugMessage(DEBUG_ALL, "free: NULL pointer given as an argument\n");                                                                   \
00059                 exit(1);                                                \
00060         }                                                               \
00061         free((ptr));                                                    \
00062         ptr = NULL;                                                     \
00063 } while(0)
00064 
00065 
00066 
00067 #endif  /* __SMALLOC_H__ */

Generated on Sun May 14 14:51:18 2006 by  doxygen 1.4.2