BUF_MEM_NEW(3ossl)

BUF_MEM_NEW πŸ’– (the 3ossl one, from the OpenSSL girlies)

okay bestie, pull up a chair, we're doing buffer today and honestly? it's giving foundational. ✨


✨ NAME ✨

BUF_MEM_new, BUF_MEM_new_ex, BUF_MEM_free, BUF_MEM_grow, BUF_MEM_grow_clean, BUF_reverse β€” the whole lil' squad that handles your simple character array structure πŸŽ€


🌸 SYNOPSIS 🌸

#include <openssl/buffer.h>

BUF_MEM *BUF_MEM_new(void);

BUF_MEM *BUF_MEM_new_ex(unsigned long flags);

void BUF_MEM_free(BUF_MEM *a);

int BUF_MEM_grow(BUF_MEM *str, int len);
size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len);

void BUF_reverse(unsigned char *out, const unsigned char *in, size_t size);

like. look at them. so organized. so iconic. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so the buffer library is the one handling simple character arrays. buffers show up all over the place in the library for various purposes, but the most notable glow-up is memory BIOs. iykyk. πŸ’…

BUF_MEM_new() allocates a brand new buffer of zero size. a tiny lil baby buffer. fresh out the box. πŸ“

BUF_MEM_new_ex() allocates a buffer with the flags you specify. and the flag BUF_MEM_FLAG_SECURE? it says the data pointer should be allocated on the secure heap β€” go peek at CRYPTO_secure_malloc(3) for the tea. πŸ”

BUF_MEM_free() frees up a buffer that already exists. and the way it does it?? the data is zeroed before freeing up, just in case the buffer is holding sensitive data. no crumbs left behind, no cap. πŸ™ˆ and if the argument is NULL? nothing happens. it just. doesn't. literally nothing. πŸ’€

BUF_MEM_grow() changes the size of an already-existing buffer to len. any data already chillin' in the buffer is preserved if it increases in size. growth without loss, we love to see it. 🌱

BUF_MEM_grow_clean() is basically BUF_MEM_grow()'s sibling but it sets any free'd or additionally-allocated memory to zero. clean girl energy. 🧚

BUF_reverse() reverses size bytes at in into out. and if in is NULL? the array gets reversed in-place. no copies, just vibes. πŸ”₯


πŸ’œ RETURN VALUES πŸ’œ

  • BUF_MEM_new() β€” returns the buffer, or NULL on error. 😭
  • BUF_MEM_free() β€” has no return value. it gives nothing and that's fine.
  • BUF_MEM_grow() and BUF_MEM_grow_clean() β€” return zero on error, or the new size (i.e., len). so like, either you ate or you flopped. 🫢

🌈 SEE ALSO 🌈

bio(7), CRYPTO_secure_malloc(3).


⭐ HISTORY ⭐

the BUF_MEM_new_ex() function was added in OpenSSL 1.1.0. a whole era. πŸ‘‘


Copyright 2000-2024 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at https://www.openssl.org/source/license.html.


and that's the whole page bestie, no notes. this was version 3.5.9, dated 2026-09-29, and it's literally a BUF_MEM_NEW(3ossl) moment. go grow a buffer, you got this πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from