From: Lasse Collin Date: Wed, 16 Jan 2008 12:46:50 +0000 (+0200) Subject: Added lzma_memlimit_count(). X-Git-Tag: upstream/5.1.3~832 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b5b13c7bb8fde6331064d21f3ebde41072480c4;p=platform%2Fupstream%2Fxz.git Added lzma_memlimit_count(). --- diff --git a/src/liblzma/api/lzma/memlimit.h b/src/liblzma/api/lzma/memlimit.h index 26ec50f..6f78289 100644 --- a/src/liblzma/api/lzma/memlimit.h +++ b/src/liblzma/api/lzma/memlimit.h @@ -93,6 +93,16 @@ extern size_t lzma_memlimit_used(const lzma_memlimit *mem); /** + * \brief Gets the number of allocations owned by the memory limitter + * + * The count does not include the helper structures; if no memory has + * been allocated with lzma_memlimit_alloc() or all memory allocated + * has been freed or detached, this will return zero. + */ +extern size_t lzma_memlimit_count(const lzma_memlimit *mem); + + +/** * \brief Allocates memory with malloc() if memory limit allows * * \param mem Pointer to a lzma_memlimit structure returned diff --git a/src/liblzma/common/memory_limitter.c b/src/liblzma/common/memory_limitter.c index 19cdefc..0983c82 100644 --- a/src/liblzma/common/memory_limitter.c +++ b/src/liblzma/common/memory_limitter.c @@ -85,6 +85,25 @@ lzma_memlimit_used(const lzma_memlimit *mem) } +extern LZMA_API size_t +lzma_memlimit_count(const lzma_memlimit *mem) +{ + // This is slow; we could have a counter in lzma_memlimit + // for fast version. I expect the primary use of this + // function to be limited to easy checking of memory leaks, + // in which this implementation is just fine. + size_t count = 0; + const lzma_memlimit_list *record = mem->list; + + while (record != NULL) { + ++count; + record = record->next; + } + + return count; +} + + extern LZMA_API void lzma_memlimit_end(lzma_memlimit *mem, lzma_bool free_allocated) {