| 1 |
'\" t |
| 2 |
.\" Copyright 2003, Andries E. Brouwer <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
.\" |
| 7 |
.TH cfree 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
cfree \- free allocated memory |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.P |
| 16 |
.B "#include <stdlib.h>" |
| 17 |
.P |
| 18 |
/* In SunOS 4 */ |
| 19 |
.BI "int cfree(void *" ptr ); |
| 20 |
.P |
| 21 |
/* In glibc or FreeBSD libcompat */ |
| 22 |
.BI "void cfree(void *" ptr ); |
| 23 |
.P |
| 24 |
/* In SCO OpenServer */ |
| 25 |
.BR "void cfree(" "unsigned int n, unsigned int size;" |
| 26 |
.BI " char " ptr [ size " * " n "], unsigned int " n ", unsigned int " size ); |
| 27 |
.P |
| 28 |
/* In Solaris watchmalloc.so.1 */ |
| 29 |
.BR "void cfree(" "size_t n, size_t size;" |
| 30 |
.BI " void " ptr [ size " * " n "], size_t " n ", size_t " size ); |
| 31 |
.fi |
| 32 |
.P |
| 33 |
.RS -4 |
| 34 |
Feature Test Macro Requirements for glibc (see |
| 35 |
.BR feature_test_macros (7)): |
| 36 |
.RE |
| 37 |
.P |
| 38 |
.BR cfree (): |
| 39 |
.nf |
| 40 |
Since glibc 2.19: |
| 41 |
_DEFAULT_SOURCE |
| 42 |
glibc 2.19 and earlier: |
| 43 |
_BSD_SOURCE || _SVID_SOURCE |
| 44 |
.fi |
| 45 |
.SH DESCRIPTION |
| 46 |
This function should never be used. |
| 47 |
Use |
| 48 |
.BR free (3) |
| 49 |
instead. |
| 50 |
Starting with glibc 2.26, it has been removed from glibc. |
| 51 |
.SS 1-arg cfree |
| 52 |
In glibc, the function |
| 53 |
.BR cfree () |
| 54 |
is a synonym for |
| 55 |
.BR free (3), |
| 56 |
"added for compatibility with SunOS". |
| 57 |
.P |
| 58 |
Other systems have other functions with this name. |
| 59 |
The declaration is sometimes in |
| 60 |
.I <stdlib.h> |
| 61 |
and sometimes in |
| 62 |
.IR <malloc.h> . |
| 63 |
.SS 3-arg cfree |
| 64 |
Some SCO and Solaris versions have malloc libraries with a 3-argument |
| 65 |
.BR cfree (), |
| 66 |
apparently as an analog to |
| 67 |
.BR calloc (3). |
| 68 |
.P |
| 69 |
If you need it while porting something, add |
| 70 |
.P |
| 71 |
.in +4n |
| 72 |
.EX |
| 73 |
#define cfree(p, n, s) free((p)) |
| 74 |
.EE |
| 75 |
.in |
| 76 |
.P |
| 77 |
to your file. |
| 78 |
.P |
| 79 |
A frequently asked question is "Can I use |
| 80 |
.BR free (3) |
| 81 |
to free memory allocated with |
| 82 |
.BR calloc (3), |
| 83 |
or do I need |
| 84 |
.BR cfree ()?\[dq]. |
| 85 |
Answer: use |
| 86 |
.BR free (3). |
| 87 |
.P |
| 88 |
An SCO manual writes: "The cfree routine is provided for compliance |
| 89 |
to the iBCSe2 standard and simply calls free. |
| 90 |
The n and size |
| 91 |
arguments to cfree are not used." |
| 92 |
.SH RETURN VALUE |
| 93 |
The SunOS version of |
| 94 |
.BR cfree () |
| 95 |
(which is a synonym for |
| 96 |
.BR free (3)) |
| 97 |
returns 1 on success and 0 on failure. |
| 98 |
In case of error, |
| 99 |
.I errno |
| 100 |
is set to |
| 101 |
.BR EINVAL : |
| 102 |
the value of |
| 103 |
.I ptr |
| 104 |
was not a pointer to a block previously allocated by |
| 105 |
one of the routines in the |
| 106 |
.BR malloc (3) |
| 107 |
family. |
| 108 |
.SH ATTRIBUTES |
| 109 |
For an explanation of the terms used in this section, see |
| 110 |
.BR attributes (7). |
| 111 |
.TS |
| 112 |
allbox; |
| 113 |
lbx lb lb |
| 114 |
l l l. |
| 115 |
Interface Attribute Value |
| 116 |
T{ |
| 117 |
.na |
| 118 |
.nh |
| 119 |
.BR cfree () |
| 120 |
T} Thread safety MT-Safe /* In glibc */ |
| 121 |
.TE |
| 122 |
.SH VERSIONS |
| 123 |
The 3-argument version of |
| 124 |
.BR cfree () |
| 125 |
as used by SCO conforms to the iBCSe2 standard: |
| 126 |
Intel386 Binary Compatibility Specification, Edition 2. |
| 127 |
.SH STANDARDS |
| 128 |
None. |
| 129 |
.SH HISTORY |
| 130 |
.\" commit 025b33ae84bb8f15b2748a1d8605dca453fce112 |
| 131 |
Removed in glibc 2.26. |
| 132 |
.SH SEE ALSO |
| 133 |
.BR malloc (3) |