FREE(3P)

πŸ’– FREE(3P) β€” bestie edition πŸ’–

okay so you're looking at FREE(3P) from the POSIX Programmer's Manual and honestly? iconic. this is the page about giving memory back. the moment where you say "ty for your service, queen, you may rest now" 🫢


✨ PROLOG ✨

so like, real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β€” so if you're on Linux, go check the corresponding Linux manual page for the actual tea on Linux behavior. orrr it might not even be implemented on Linux at all. no cap. πŸ™ˆ


🌸 NAME 🌸

free β€” free allocated memory

like. she frees. that's her whole job. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <stdlib.h>

void free(void *ptr);

one function, one argument, zero return value. minimalism is the vibe. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the functionality on this reference page is aligned with the ISO C standard. any conflict between the requirements described here and the ISO C standard is unintentional β€” this volume of POSIX.1‐2017 defers to the ISO C standard. so if they ever beef, ISO C wins. periodt. πŸ‘‘

the free() function shall cause the space pointed to by ptr to be deallocated β€” that is, made available for further allocation. think of it like clearing your camera roll so you have storage again. 🧹

if ptr is a null pointer, no action shall occur. nothing happens. she's chill. 😌

otherwise β€” and this is the part where you need to PAY ATTENTION bestie β€” if the argument does not match a pointer earlier returned by a function in POSIX.1‐2008 that allocates memory as if by malloc(), or if the space has been deallocated by a call to free() or realloc(), the behavior is undefined. πŸ’€

⚠️ and any use of a pointer that refers to freed space results in undefined behavior. that's a use-after-free. that's the villain origin story. do not do it. 🚫

πŸ’œ RETURN VALUE πŸ’œ

the free() function shall not return a value.

she gives you nothing back. not even a vibe. she just takes the pointer and moves on. πŸ’…


🌈 ERRORS 🌈

no errors are defined.

zero. none. she doesn't have bad days. (but also, the next sections are informative, so keep reading, bestie.)


πŸ“ EXAMPLES πŸ“

none.

yeah. the examples section is empty. it's giving minimal effort but honestly? the function is like four words long. iykyk. 😭


🧚 APPLICATION USAGE 🧚

there is now no requirement for the implementation to support the inclusion of <malloc.h>.

so like, that old header? not required anymore. glow-up achieved. ✨


⭐ RATIONALE ⭐

none.


🌸 FUTURE DIRECTIONS 🌸

none.


πŸ‘‘ SEE ALSO πŸ‘‘

  • calloc()
  • malloc()
  • posix_memalign()
  • realloc()

and the Base Definitions volume of POSIX.1‐2017, <stdlib.h>

like the whole friend group. they all show up together. 🫢


portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.

in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. (so the original is the main character, basically. πŸ‘‘) the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie!! πŸ’• courtesy of IEEE/The Open Group, dated 2017, filed under FREE(3P). go free your memory responsibly and never touch a pointer after you've freed it, ok?? mwah. πŸ’‹πŸŒˆβœ¨

πŸ“¦ where this page comes from