MALLOC(3)
πΈ 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 pointerptr(so like, don't assume it moved, but also don't assume it didn't, iykyk) - π on failure β it returns a
NULLpointer, anderrnois set toENOMEMif 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
- Copyright (c) 1980, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms