malloc.c の内部関数で一番 malloc() のイメージにふさわしい仕事をするのが sysmalloc() 関数です。
2265 /* 2266 sysmalloc handles malloc cases requiring more memory from the system. 2267 On entry, it is assumed that av->top does not have enough 2268 space to service request for nb bytes, thus requiring that av->top 2269 be extended or replaced. 2270 */ 2271 2272 static void * 2273 sysmalloc (INTERNAL_SIZE_T nb, mstate av)
この関数は新規の割り当てに使われます。
もう一つ頻繁に使われるのが alloc_perturb() 関数です。
1882 static int perturb_byte;
1883
1884 static void
1885 alloc_perturb (char *p, size_t n)
1886 {
1887 if (__glibc_unlikely (perturb_byte))
1888 memset (p, perturb_byte ^ 0xff, n);
1889 }
1890
1891 static void
1892 free_perturb (char *p, size_t n)
1893 {
1894 if (__glibc_unlikely (perturb_byte))
1895 memset (p, perturb_byte, n);
1896 }perturb_byte が 0 でないならポインター p が指す n バイトに対して perturb_byte ^ 0xff を設定します。
Copyright 2018-2019, by Masaki Komatsu