From e26c4fd2a22d047f71188ba6b876f565237482cf Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 16 Sep 2004 16:53:39 +0000 Subject: [PATCH] Some fixes to memory debugging code. Exclude internal commands formats & segtypes from install. --- WHATS_NEW | 2 ++ lib/mm/dbg_malloc.c | 17 ++++++++++------- lib/mm/pool-debug.c | 5 ++++- tools/Makefile.in | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 843f9f072..83fe0dc64 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,7 @@ Version 2.00.24 - ===================================== + Some fixes to memory debugging code. + Exclude internal commands formats & segtypes from install. Version 2.00.23 - 15th September 2004 ===================================== diff --git a/lib/mm/dbg_malloc.c b/lib/mm/dbg_malloc.c index 42f434acf..47cecf8c0 100644 --- a/lib/mm/dbg_malloc.c +++ b/lib/mm/dbg_malloc.c @@ -29,11 +29,13 @@ struct memblock { }; static struct { - unsigned int blocks, mblocks; + unsigned block_serialno;/* Non-decreasing serialno of block */ + unsigned blocks_allocated; /* Current number of blocks allocated */ + unsigned blocks_max; /* Max no of concurrently-allocated blocks */ unsigned int bytes, mbytes; } _mem_stats = { -0, 0, 0, 0}; +0, 0, 0, 0, 0}; static struct memblock *_head = 0; static struct memblock *_tail = 0; @@ -65,7 +67,7 @@ void *malloc_aux(size_t s, const char *file, int line) /* setup fields */ nb->magic = nb + 1; nb->length = s; - nb->id = ++_mem_stats.blocks; + nb->id = ++_mem_stats.block_serialno; nb->next = 0; nb->prev = _tail; @@ -89,8 +91,9 @@ void *malloc_aux(size_t s, const char *file, int line) *ptr++ = (char) nb->id; } - if (_mem_stats.blocks > _mem_stats.mblocks) - _mem_stats.mblocks = _mem_stats.blocks; + _mem_stats.blocks_allocated++; + if (_mem_stats.blocks_allocated > _mem_stats.blocks_max) + _mem_stats.blocks_max = _mem_stats.blocks_allocated; _mem_stats.bytes += s; if (_mem_stats.bytes > _mem_stats.mbytes) @@ -140,8 +143,8 @@ void free_aux(void *p) else _tail = mb->prev; - assert(_mem_stats.blocks); - _mem_stats.blocks--; + assert(_mem_stats.blocks_allocated); + _mem_stats.blocks_allocated--; _mem_stats.bytes -= mb->length; /* free the memory */ diff --git a/lib/mm/pool-debug.c b/lib/mm/pool-debug.c index 482a1a290..a56f24a07 100644 --- a/lib/mm/pool-debug.c +++ b/lib/mm/pool-debug.c @@ -83,7 +83,7 @@ static void _append_block(struct pool *p, struct block *b) static struct block *_new_block(size_t s, unsigned alignment) { - static char *_oom = "Out of memory"; + static const char *_oom = "Out of memory"; /* FIXME: I'm currently ignoring the alignment arg. */ size_t len = sizeof(struct block) + s; @@ -180,10 +180,13 @@ int pool_grow_object(struct pool *p, const void *buffer, size_t delta) if (p->object) { memcpy(new->data, p->object->data, p->object->size); + dbg_free(p->object->data); dbg_free(p->object); } p->object = new; + memcpy(new->data + size - delta, buffer, delta); + return 1; } diff --git a/tools/Makefile.in b/tools/Makefile.in index ce8ff2036..05eb51472 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -109,7 +109,7 @@ liblvm2cmd.so: liblvm2cmd.a $(LDDEPS) .commands: commands.h cmdnames.h Makefile $(CC) -E -P cmdnames.h 2> /dev/null | \ - egrep -v '^ *(|#.*|dumpconfig|help|pvdata|version) *$$' > .commands + egrep -v '^ *(|#.*|dumpconfig|formats|help|pvdata|segtypes|version) *$$' > .commands .PHONY: install_cmdlib_dynamic install_cmdlib_static \ install_tools_dynamic install_tools_static