Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages

Manual Reference Pages  -  CRYPTO_FREE (3)

.ds Aq ’


OPENSSL_malloc_init, OPENSSL_malloc, OPENSSL_zalloc, OPENSSL_realloc, OPENSSL_free, OPENSSL_clear_realloc, OPENSSL_clear_free, CRYPTO_malloc, CRYPTO_zalloc, CRYPTO_realloc, CRYPTO_free, OPENSSL_strdup, OPENSSL_strndup, OPENSSL_memdup, OPENSSL_strlcpy, OPENSSL_strlcat, CRYPTO_clear_realloc, CRYPTO_clear_free, CRYPTO_get_mem_functions, CRYPTO_set_mem_functions, CRYPTO_set_mem_debug, CRYPTO_mem_ctrl, OPENSSL_mem_debug_push, OPENSSL_mem_debug_pop, CRYPTO_mem_debug_push, CRYPTO_mem_debug_pop, CRYPTO_mem_leaks, CRYPTO_mem_leaks_fp - Memory allocation functions



 #include <openssl/crypto.h>

 int OPENSSL_malloc_init(void)

 void *OPENSSL_malloc(size_t num)
 void *OPENSSL_zalloc(size_t num)
 void *OPENSSL_realloc(void *addr, size_t num)
 void OPENSSL_free(void *addr)
 char *OPENSSL_strdup(const char *str)
 char *OPENSSL_strndup(const char *str, size_t s)
 void *OPENSSL_clear_realloc(void *p, size_t old_len, size_t num)
 void OPENSSL_clear_free(void *str, size_t num)
 void OPENSSL_cleanse(void *ptr, size_t len);

 void *CRYPTO_malloc(size_t num, const char *file, int line)
 void *CRYPTO_zalloc(size_t num, const char *file, int line)
 void *CRYPTO_realloc(void *p, size_t num, const char *file, int line)
 void CRYPTO_free(void *str)
 char *CRYPTO_strdup(const char *p, const char *file, int line)
 char *CRYPTO_strndup(const char *p, size_t num, const char *file, int line)
 void *CRYPTO_clear_realloc(void *p, size_t old_len, size_t num, const char *file, int line)
 void CRYPTO_clear_free(void *str, size_t num)

 void CRYPTO_get_mem_functions(
         void *(**m)(size_t, const char *, int),
         void *(**r)(void *, size_t, const char *, int),
         void (**f)(void *))
 int CRYPTO_set_mem_functions(
         void *(*m)(size_t, const char *, int),
         void *(*r)(void *, size_t, const char *, int),
         void (*f)(void *))

 int CRYPTO_set_mem_debug(int onoff)


 int CRYPTO_mem_ctrl(int mode);

 int OPENSSL_mem_debug_push(const char *info)
 int OPENSLS_mem_debug_pop)(void)

 int CRYPTO_mem_debug_push(const char *info, const char *file, int line);

 void CRYPTO_mem_leaks(BIO *b);
 void CRYPTO_mem_leaks(FILE *fp);


OpenSSL memory allocation is handled by the OPENSSL_xxx API. These are generally macro’s that add the standard C __FILE__ and __LINE__ parameters and call a lower-level CRYPTO_xxx API. Some functions do not add those parameters, but exist for consistency.

OPENSSL_malloc_init() sets the lower-level memory allocation functions to their default implementation. It is generally not necessary to call this, except perhaps in certain shared-library situations.

OPENSSL_malloc(), OPENSSL_realloc(), and OPENSSL_free() are like the C malloc(), realloc(), and free() functions. OPENSSL_zalloc() calls memset() to zero the memory before returning.

OPENSSL_clear_realloc() and OPENSSL_clear_free() should be used when the buffer at addr holds sensitive information. The old buffer is filled with arbitrary data by calling OPENSSL_cleanse() before ultimately calling OPENSSL_free().

OPENSSL_strdup(), OPENSSL_strndup() and OPENSSL_memdup() are like the equivalent C functions, except that memory is allocated by calling the OPENSSL_malloc() and should be releaed by calling OPENSSL_free().

OPENSSL_strlcpy(), OPENSSL_strlcat() and OPENSSL_strnlen() are equivalents of the common C library functions and are provided for portability.

If no allocations have been done, it is possible to swap out the default implementations and replace them with alternate versions, or wrappers that do some additional housekeeping and then defer to the OpenSSL implementation. The CRYPTO_get_mem_functions() function fills in the function pointers for with the current functions (normally, and by default, CRYPTO_malloc(), CRYPTO_realloc(), and CRYPTO_free()). The CRYPTO_set_mem_functions() specifies a different set of functions. If any of m, r, or f are NULL, then the function is not changed.

The default implementation can include some debugging capability (if enabled at build-time). This adds some overhead by keeping a list of all memory allocations, and removes items from the list when they are free’d. This is most useful for identifying memory leaks. CRYPTO_set_mem_debug() turns this tracking on and off. It is normally called at startup, but can be called at any time.

CRYPTO_mem_ctrl() provides fine-grained control of memory leak tracking. To enable tracking call CRYPTO_mem_ctrl() with a mode argument of the CRYPTO_MEM_CHECK_ON. To disable tracking call CRYPTO_mem_ctrl() with a mode argument of the CRYPTO_MEM_CHECK_OFF. The CRYPTO_MEM_CHECK_DISABLE and CRYPTO_MEM_CHECK_ENABLE modes are used internally within OpenSSL to temporarily suspend and resume tracking.

While checking memory, it can be useful to store additional context about what is being done. For example, identifying the field names when parsing a complicated data structure. OPENSSL_mem_debug_push() (which calls CRYPTO_mem_debug_push()) attachs an identifying string to the allocation stack. This must be a global or other static string; it is not copied. OPENSSL_mem_debug_pop() removes identifying state from the stack.

At the end of the program, calling CRYPTO_mem_leaks() or CRYPTO_mem_leaks_fp() will report all leaked memory, writing it to the specified BIO b or FILE fp. These functions return 1 if there are no leaks, 0 if there are leaks and -1 if an error occurred.


OPENSSL_malloc_init(), OPENSSL_free(), OPENSSL_clear_free() CRYPTO_free(), CRYPTO_clear_free() and CRYPTO_get_mem_functions() return no value.

CRYPTO_mem_leaks() and CRYPTO_mem_leaks_fp() return 1 if there are no leaks, 0 if there are leaks and -1 if an error occurred.

OPENSSL_malloc(), OPENSSL_zalloc(), OPENSSL_realloc(), OPENSSL_clear_realloc(), CRYPTO_malloc(), CRYPTO_zalloc(), CRYPTO_realloc(), CRYPTO_clear_realloc(), OPENSSL_strdup(), and OPENSSL_strndup() return a pointer to allocated memory or NULL on error.

CRYPTO_set_mem_functions() and CRYPTO_set_mem_debug() return 1 on success or 0 on failure (almost always because allocations have already happened).

CRYPTO_mem_ctrl() returns the previous value of the mode.

OPENSSL_mem_debug_push() and OPENSSL_mem_debug_pop() return 1 on success or 0 on failure.

Search for    or go to Top of page |  Section 3 |  Main Index

1.1.0-pre3 OPENSSL_MALLOC (3) 2016-02-15

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.