MALLOC(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

🌸 MALLOC(3) β€” Library Functions Manual 🌸

okay so bestie, real talk: yes, the page is called MALLOC(3) and no, we're not talking about malloc β€” it's a whole situation, we'll get there. This is the Library Functions Manual entry, and it's giving "small function, big feelings." Let's go πŸ’…


✨ NAME ✨

reallocf β€” the memory reallocation function that actually cleans up after itself πŸŽ€


πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc) β€” like, the standard-est of standard, no cap πŸ’–


🧚 SYNOPSIS 🧚

#include <stdlib.h>

void *
reallocf(void *ptr, size_t size);

look at her. two params, no drama (well β€” one specific drama, see below) ✨


πŸ’« DESCRIPTION πŸ’«

okay so here's the tea β˜•: reallocf() is literally identical to the realloc() function β€” same energy, same vibes β€” except for one iconic little twist: it will free the passed pointer when the requested memory cannot be allocated. 🫢

and that's the whole point, bestie. this is a FreeBSD specific API, and it was designed to ease the problems with traditional coding styles for realloc() causing memory leaks in libraries. like, it exists purely to save you from yourself. main character energy, honestly πŸ‘‘

⚠️ real talk though: because it frees your pointer on failure, you do not get to keep using that original pointer afterward. she's gone. don't touch. πŸ™ˆ

πŸ”₯ RETURN VALUES πŸ”₯

  • ✨ on success β€” reallocf() returns a pointer to the allocated memory, which may be identical to the passed pointer ptr (so like, don't assume it moved, but also don't assume it didn't, iykyk)
  • πŸ’€ on failure β€” it returns a NULL pointer, and errno is set to ENOMEM if the error was the result of an allocation failure

and one more time for the people in the back β€” the reallocf() function deletes the original buffer when an error occurs. that's the entire personality of this function. it's a feature, not a bug, but it will absolutely wreck you if you forget 😭


πŸ¦‹ SEE ALSO πŸ¦‹

  • realloc(3) β€” her more cautious, leak-prone cousin 🌈

⭐ HISTORY ⭐

the reallocf() function first appeared in FreeBSD 3.0. a legend was born πŸ”₯


anyway that's the whole page, you ate that reading it πŸ’– this one shipped in the Debian build of the manual, dated January 31, 2010 β€” so yes she's vintage, and yes she still serves πŸŽ€ go free your pointers responsibly, bestie 🌈

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms