Next: , Previous: Symbol Space Functions, Up: libsieve


3.4.5 Memory Allocation

The following functions act as their libc counterparts. The allocated memory is associated with the mach argument and is automatically freed upon the call to mu_sieve_machine_destroy (mach).

— Function: void * mu_sieve_malloc (mu_sieve_machine_t mach, size_t size)

Allocates size bytes and returns a pointer to the allocated memory.

— Function: char * mu_sieve_mstrdup (mu_sieve_machine_t mach, const char *str)

This function returns a pointer to a new string which is a duplicate of the string str.

— Function: void * mu_sieve_mrealloc (mu_sieve_machine_t mach, void *ptr, size_t size)

Changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged to the minimum of the old and new sizes; newly allocated memory will be uninitialized. If ptr is NULL, the call is equivalent to mu_sieve_malloc(mach, size); if size is equal to zero, the call is equivalent to mu_sieve_mfree(ptr). Unless ptr is NULL, it must have been returned by an earlier call to mu_sieve_malloc() or mu_sieve_mrealloc().

— Function: void mu_sieve_mfree (mu_sieve_machine_t mach, void *ptr)

mu_sieve_mfree() frees the memory space pointed to by ptr and detaches it from the destructor list of mach. The ptr must have been returned by a previous call to mu_sieve_malloc() or mu_sieve_mrealloc(). Otherwise, or if mu_sieve_mfree(ptr) has already been called before, undefined behaviour occurs.

If ptr is NULL, no operation is performed.