1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
.\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\" License.
.\" Modified Sat Jul 24 19:00:59 1993 by Rik Faith (faith@cs.unc.edu)
.\" Clarification concerning realloc, iwj10@cus.cam.ac.uk (Ian Jackson), 950701
.\" Documented MALLOC_CHECK_, Wolfram Gloger (wmglo@dent.med.uni-muenchen.de)
.\"
.\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
.\" Translated Wed 12 Aug 1998 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
.\" Modified Sun 18 Dec 1998 by NAKANO Takeo
.\" Modified Wed 23 Aug 2000 by NAKANO Takeo
.\" Modified Sat 19 May 2001 by Kentaro Shirakata <argrath@ub32.org>
.\" Modified Thu 13 Dec 2001 by Kentaro Shirakata <argrath@ub32.org>
.\"
.\" WORD: OOM killer
.TH MALLOC 3 "April 4, 1993" "GNU" "Linux Programmer's Manual"
.SH ̾
calloc, malloc, free, realloc \- ưŪʥγƤȲԤ
.SH
.nf
.B #include <stdlib.h>
.sp
.BI "void *calloc(size_t " "nmemb" ", size_t " "size" );
.nl
.BI "void *malloc(size_t " "size" );
.nl
.BI "void free(void " "*ptr" );
.nl
.BI "void *realloc(void " "*ptr" ", size_t " "size" );
.fi
.SH
.B calloc()
.I size
ХȤ
.I nmemb
Ĥʤ˥ơ
Ƥ줿Фݥ֤
ƤϿͥ (ӥåȤΥХ) ˥åȤ롣
.PP
.B malloc()
.I size
ХȤơ
Ƥ줿Фݥ֤
Ƥϥꥢʤ
.PP
.B free()
ϥݥ
.I ptr
ؤ֤롣Υݥϡ˸ƤӽФ줿
.BR malloc() ,
.BR calloc() ,
.B realloc
Τ줫֤ͤǤʤФʤʤ
ʳΥݥꤷꡢǤ
.BI "free(" "ptr" )
¹ԤƤꤷưƤʤ
.I ptr
.B NULL
ξˤϡʤưԤʤ
.PP
.B realloc
ϡݥ
.I ptr
֥åΥѹ
.I size
ХȤˤ롣
ΥΤۤΥ֥å˴ޤޤƤѹʤ
Ƥ줿ƤϽʤ
.I ptr
.B NULL
ξˤϡθƤӽФ
.B malloc(size)
Ǥ롣 size 0 ξˤϡθƤӽФ
.BI "free(" "ptr" )
Ǥ롣
.I ptr
(
.B NULL
Ǥʤ)˸ƤӽФ줿
.BR malloc() ,
.BR calloc() ,
.B realloc()
Τ줫֤ͤǤʤФʤʤ
.SH ֤
.BR calloc() " " malloc()
֤ͤϡƤ줿ؤΥݥǤ롣
ϤѿŬ褦˥饤ȤƤ롣
˼Ԥ
.B NULL
֤롣
.PP
.B free()
֤ͤʤ
.PP
.B realloc()
Ͽ˳Ƥ줿ؤΥݥ֤
ϤѿŬ褦˥饤ȤƤꡢ
.I ptr
Ȥϰۤʤ뤫⤷ʤ
˼Ԥ
.B NULL
֤롣
.I size
0 äˤϡNULL 뤤
.IR free ()
ϤȤǤݥ֤롣
.B realloc()
ԤˤϡΥ֥åѹʤ
Ĥޤꡢ줿ư줿Ϥʤ
.SH
ANSI-C
.SH Ϣ
.BR brk (2),
.BR posix_memalign (3)
.SH
Unix98 ɤǤϡ
.BR malloc() ", " calloc() ", " realloc()
ϼ¹Ԥ˼ԤȤ
.I errno
ENOMEM ꤹ뤳ȤˤʤäƤ롣
Glibc ǤϤ줬Ƥ뤳ȤꤷƤ
(ޤΥ롼 glibc СǤϤäƤ)
⤷ĿŪ˼ malloc Ȥ malloc
.I errno
ꤷʤˤϡ
.I errno
ͳ֤˼Ԥ饤֥롼뤫⤷ʤ
.LP
.BR malloc() ,
.BR free() ,
.B realloc()
ʤɤˤΤϡ
ۤȤɤξϥҡפ˲ (corruption) Ǥ롣
㤨гƤ줿ΰСե롢
Ʊݥ free 롢ʤɤˤ롣
.PP
ǶΥС Linux libc (5.4.23 ʹ) GNU libc (2.x) Ǥϡ
malloc ưĶѿˤäǤ褦ʼƤ롣
.B MALLOC_CHECK_
ꤵƤȡüʼѤ졢
ñʥ顼ˤѤ뤳ȤǤ褦ˤʤ (Ψϰʤ)㤨
.B free()
ƱٸƤӽФƤޤ
1 ХȤԤƤޤ (off-by-one Х) ʤɤ롣
Υ顼ƤɤȤǤ櫓ǤϤʤ
ξˤϥäƤޤ
.B MALLOC_CHECK_
0 ˥åȤƤȡҡפ˲ۤä̵뤹롣
1 ˥åȤƤȡǥåɸ२顼Ϥɽ롣
2 ˥åȤƤȡ
.B abort()
ƤӽФ롣 2 ʾȤƤϡ
ºݤΥץΥå夬äȤȤ˵ꡢ
θõФΤ˺ʾʤɤ
.PP
Linux ϳڴŪάѤƤ롣
ϡ
.B malloc()
NULL Ǥʤ֤ͤȤ꤬ºݤѲǽǤ뤳Ȥ
ݾڤʤȤ̣Ƥ롣
ƥब֤ˤʤäȤ
̾⤤ (OOM killer) ˤäưĤޤʣ
ץ롣
|