00001 /***************************************************************************** 00002 * vlc_memory.h: Memory functions 00003 ***************************************************************************** 00004 * Copyright (C) 2009 the VideoLAN team 00005 * 00006 * Authors: JP Dinger <jpd at videolan dot org> 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License along 00019 * with this program; if not, write to the Free Software Foundation, Inc., 00020 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 00021 *****************************************************************************/ 00022 00023 #ifndef VLC_MEMORY_H 00024 #define VLC_MEMORY_H 1 00025 00026 #include <stdlib.h> 00027 00028 /** 00029 * \file 00030 * This file deals with memory fixups 00031 */ 00032 00033 /** 00034 * \defgroup memory Memory 00035 * @{ 00036 */ 00037 00038 /** 00039 * This wrapper around realloc() will free the input pointer when 00040 * realloc() returns NULL. The use case ptr = realloc(ptr, newsize) will 00041 * cause a memory leak when ptr pointed to a heap allocation before, 00042 * leaving the buffer allocated but unreferenced. vlc_realloc() is a 00043 * drop-in replacement for that use case (and only that use case). 00044 */ 00045 static inline void *realloc_or_free( void *p, size_t sz ) 00046 { 00047 void *n = realloc(p,sz); 00048 if( !n ) 00049 free(p); 00050 return n; 00051 } 00052 00053 /** 00054 * @} 00055 */ 00056 00057 #endif
1.5.6