TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: JUHA-MATTI TAPIO
from: GEORGE WHITE
date: 1998-03-31 09:42:00
subject: free`ing memory

Hi,
You asked:
JT>Just something I began wondering last night.
JT>Since it's good coding practise to free() everything
JT>allocated with malloc(), should I also free() those blocks
JT>of memory which are allocated by other functions (such as
JT>fopen())?
No. You only free() anything _you_ allocate withe malloc(). Any memory
allocated by system calls will (in a good library) be freed by the
corresponding termination call. So if fopen() allocates any memory
buffers fclose() will de-allocate them.
Officially you have no way of knowing how any specific library function
has allocated any memory it requires so there is nothing you should have
to do to reclaim it. Most library functions that require memory buffers
either use a static buffer or expect you to provide a pointer to a
suitable buffer as a function parameter.
George
 * SLMR 2.1a * Wastebasket: Something to throw things near.
--- Maximus/2 3.01
---------------
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.