---
name: "wnmemd"
section: "3"
platform: "linux"
package: "libwn-dev"
version: "6.0-17"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/wnmemd"
---

# wnmemd(3)

debugging aids for applications using wnmem

## NAME

wn\_print\_all\_groups\_mem\_used, wn\_mem\_in\_group, wn\_print\_gp\_stack, wn\_gplabel, wn\_gp\_fill, wn\_gp\_pad, wn\_stack\_fill, wn\_gp\_trap\_address, wn\_allmem\_verify, wn\_group\_verify, wn\_mem\_used, wn\_group\_mem\_used, wn\_print\_mem\_used, wn\_print\_group\_mem\_used - debugging aids for applications using wnmem

## SYNOPSIS

```
#include <wn/wnlib.h>

wn_gp_fill()

wn_gp_pad()

wn_stack_fill()

wn_gp_trap_address(address)
ptr address;

wn_allmem_verify()

wn_group_verify(group)
wn_memgp group;

int wn_mem_used()

int wn_group_mem_used(group)
wn_memgp group;

wn_print_mem_used()

wn_print_group_mem_used(group)
wn_memgp group;

wn_print_all_groups_mem_used()

bool wn_mem_in_group(p,group)
ptr p;
wn_memgp group;

wn_print_gp_stack()

wn_gplabel(label)
char label[];
```

## DESCRIPTION

These routines aid in debugging applications that use  wnmem.  In particular, these routines help detect the following problems:

1\)  use of uninitialized allocated memory

2\)  use of memory that has already been freed

3\)  array overflows and wild stores

4\)  leakage of memory.  Memory is lost but not freed.

**wn\_gp\_fill** helps detect problems 1 and 2 above.  It should be called before any of the wnmem calls.  If **wn\_gp\_fill** has been called, **wn\_alloc** fills memory it returns with 'a' characters, ensuring that this memory is not **NULL**.   Application code that is relying on this memory to be **NULL** will probably crash immediately and reliably. Further, **wn\_gp\_free** and **wn\_free** fill memory they free with 'f' characters; application code that continues  to rely on this memory will probably crash immediately and reliably.

**wn\_gp\_pad** helps detect problem 3 above.  It should be called before any of the wnmem calls.  If **wn\_gp\_pad** has been called, **wn\_alloc** and **wn\_zalloc** allocate an extra block of memory called a pad, in addition to the requested memory.  The pad memory is initialized to a known value.  Because the pad is contiguous with the requested memory, it will probably be overwritten in the event of an array overflow or a wild store. **wn\_allmem\_verify** checks if any of the pads are changed; if so it crashes with a message.  Use **wn\_allmem\_verify** to binary search the application for the problem.

**wn\_allmem\_verify** checks the memory allocator for inconsistancies. If **wn\_gp\_pad** has been called, it helps detect array overflows and wild stores.

**wn\_group\_verify** verifies an individual memory group.

**wn\_print\_mem\_used** prints the total amount of memory allocated but not freed, which is helpful for detecting memory leaks.

**wn\_print\_group\_mem\_used** prints the total amount of memory allocated but not freed in the memory group, which is helpful for detecting memory leaks.

**wn\_print\_all\_groups\_mem\_used** prints the total amount of memory allocated but not freed in each memory group separately, then prints a total for all groups.

**wn\_mem\_in\_group** returns TRUE iff pointer *p* was allocated from memory group *group*.

**wn\_print\_gp\_stack** prints the memory group stack.

**wn\_gplabel** assigns a char string label to the current group for debugging purposes.  Other routines use this label if it is available.  Use **wn\_gplabel** immediately after [wn\_gpmake(3)](/wn_gpmake/3.md).

**wn\_gp\_trap\_address** causes allocations of memory at *address* to crash.  Useful for finding where a pointer is allocated.

## SEE ALSO

wnmem, wnmlc *man/papers/heisen.bug*

## AUTHOR

Will Naylor
