---
name: "libressl-BUF_MEM_new"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-BUF_MEM_new"
---

# libressl-BUF\_MEM\_new(3)

simple character arrays structure

## NAME

**BUF\_MEM\_new**, **BUF\_MEM\_free**, **BUF\_MEM\_grow**, **BUF\_MEM\_grow\_clean** – simple character arrays structure

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/buffer.h\>**

*BUF\_MEM* *\**\

**BUF\_MEM\_new**(*void*);

*void*\

**BUF\_MEM\_free**(*BUF\_MEM \*a*);

*int*\

**BUF\_MEM\_grow**(*BUF\_MEM \*str*, *size\_t len*);

*int*\

**BUF\_MEM\_grow\_clean**(*BUF\_MEM \*str*, *size\_t len*);

## DESCRIPTION

The buffer library handles simple character arrays. Buffers are used for various purposes in the library, most notably memory BIOs.

The library uses the *BUF\_MEM* structure defined in buffer.h:

```
typedef struct buf_mem_st {
	size_t length;	/* current number of bytes */
	char *data;
	size_t max;	/* size of buffer */
} BUF_MEM;
```

*length* is the current size of the buffer in bytes; *max* is the amount of memory allocated to the buffer. There are three functions which handle these and one miscellaneous function.

**BUF\_MEM\_new**() allocates a new buffer of zero size.

**BUF\_MEM\_free**() frees up an already existing buffer. The data is zeroed before freeing up in case the buffer contains sensitive data. If *a* is a NULL pointer, no action occurs.

**BUF\_MEM\_grow**() changes the size of an already existing buffer to *len*. Any data already in the buffer is preserved if it increases in size.

**BUF\_MEM\_grow\_clean**() is similar to **BUF\_MEM\_grow**(), but it sets any freed or additionally allocated memory to zero.

## RETURN VALUES

**BUF\_MEM\_new**() returns the buffer or NULL on error.

**BUF\_MEM\_grow**() and **BUF\_MEM\_grow\_clean**() return zero on error or the new size (i.e. *len*).

## SEE ALSO

BIO\_new(3), BIO\_s\_mem(3)

## HISTORY

**BUF\_MEM\_new**(), **BUF\_MEM\_free**(), and **BUF\_MEM\_grow**() first appeared in SSLeay 0.6.0. All these functions  have been available since OpenBSD 2.4.

**BUF\_MEM\_grow\_clean**() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2.
