---
name: "memalloc"
section: "3"
platform: "linux"
package: "libnessus-dev"
version: "1.0.10-2"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/memalloc"
---

# memalloc(3)

allocate classified memory preclassify vreclassify sreclassify - reclassify memory set\_memblock\_max, xrealloc, xfree - administrate classified memory

## NAME

pmalloc, vmalloc, smalloc - allocate classified memory\
 preclassify vreclassify sreclassify - reclassify memory\
 set\_memblock\_max, xrealloc, xfree - administrate classified memory

## SYNOPSIS

```
#include <peks.h>

void *pmalloc (size_t size),
     *vmalloc (size_t size),
     *smalloc (size_t size);

void preclassify (void *mem_ptr),
     vreclassify (void *mem_ptr),
     sreclassify (void *mem_ptr);

unsigned set_memblock_max (size_t max_size);

void *xrealloc (void *mem_ptr, size_t new_size);

void xfree (void *mem_ptr);
```

## DESCRIPTION

The functions here provide a substitute for the standard dynamic memory functions **malloc()**, **calloc()**, **free()**,  and **realloc()**.  Although based on those functions, the new memory functions *must not* be intermixed with them:  allocating memory with **pmalloc()** and freeing it with **free()** (or vv.) results in undefined system behavior and leads most certainly to a program crash.

Classified memory as allocated with **pmalloc()**, **vmalloc()**,  end **smalloc()** comes in three flavours: **p**ublic, pri**v**ate, and **s**ecure. All memory allocated by any of the classified memory functions is zero-initialized.  The allocator functions accept 0 as a valid *size* argument.

Public memory allocated with **pmalloc()** is the same zero-initialized memory type **calloc()** would return, as well. The only difference is, that it cannot be reclassified (using **vreclassify()** for instance) and must be deallocated with **free()** instad of **xfree()**.

Private memory allocated with **pmalloc()** is zero-initialized and will be overwritten in **xfree()** before given back to the operating system.

Secure memory allocated with **smalloc()** is handled similar to private memory but will be overwritten with random data when deallocated in **xfree()**.

The functions **preclassify()**, **vreclassify()**, and **sreclassify()** reschedule the clean up procedure in **xfree()** to work as **p**ublic, pri**v**ate, or **s**ecure.  Argument is a memory pointer as returned from any of the allocator functions (for instance **pmalloc()**) for classified memory.

With **xrealloc()**, a memory block already allocated will be changed, or reallocated.  When the memory block is extended, the new part will be zero-initialized, when it is shrunk, the deallocated part will be treated as in **xfree()**. The re-allocator function accepts 0 as a valid *new\_size* argument.

All functions that return a memory pointer will not work with sizes  larger than an implementation dependent default value, currently 1MBytes. With the function **set\_memblock\_max()** this maximal block size can be increased, or decreased. Function argument *max\_size* is the new limit, to be suggested.

## RETURN VALUE

All functions that return a memory pointer will never return NULL. A condition that would result in a NULL pointer causes the program to abort.

The function **set\_memblock\_max()** returns the size of the maximal data block that could be allocated when the function was invoked.

## CAVEAT

Using **xmalloc()** for a non-public memory block will *always* return a new memory area while the old one is freed.

## ENVIRONMENT VARIABLES

- **HOME**

  The path to the user's home directory.

## SEE ALSO

[**malloc**(3)](/malloc/3.md), [**calloc**(3)](/calloc/3.md), [**free**(3)](/free/3.md), [**realloc**(3)](/realloc/3.md)

## AUTHOR

The **peks** package where these functions belong to was written by Jordan Hrycaj \<jordan@teddy-net.com\>, originally to support the **nessus** security scanner.
