libcmle documentation

(c) 2008 Steffen Wendzel (steffen (at) ploetner-it (dot) de)

file version 0.1, last edit: jan-22-2008, 15:01, by: swendzel

libcmle memory related functions

libcmle provides functions to make the use of dynamic memory more seucre.

Syntax

_mzfree zeros memory before free'ing it.

void _mzfree(void *ptr, size_t len);

_mzfree() overwrites len bytes of ptr with zeros ('\0') before calling free(ptr).

RETURN VALUES

_mzfree() doesn't return anything.

Example

#include <iostream>
#include <libcmle.h>

int
main()
{
        char *x, *y;

        x = (char *)malloc(1000);
        strcpy(x, "Hello");
        y = x;

        printf("y=%s\n", y);
	/* calling free(x) is not secure and 'y' will still point to
	 * the memory location what will output "Hello" again.
	 */
        // free(x);
        // printf("y=%s\n", y);


	/* because of this, use the secure _mzfree() instead */
	_mzfree(x, strlen(x));
        printf("y=%s\n", y);
	
	return 0;
}