1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Allocating and freeing memory
6 // Copyright (C) 2007 Lasse Collin
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 ///////////////////////////////////////////////////////////////////////////////
24 extern void * lzma_attribute((malloc))
25 lzma_alloc(size_t size, lzma_allocator *allocator)
27 // Some malloc() variants return NULL if called with size == 0.
33 if (allocator != NULL && allocator->alloc != NULL)
34 ptr = allocator->alloc(allocator->opaque, 1, size);
38 #if !defined(NDEBUG) && defined(HAVE_MEMSET)
39 // This helps to catch some stupid mistakes, but also hides them from
40 // Valgrind. Uncomment when useful.
42 // memset(ptr, 0xFD, size);
50 lzma_free(void *ptr, lzma_allocator *allocator)
52 if (allocator != NULL && allocator->free != NULL)
53 allocator->free(allocator->opaque, ptr);