Become a memory accounting amateur

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-08-27 00:00:00 +00:00
parent 1e969e832f
commit efc4205416
10 changed files with 411 additions and 65 deletions

26
userland/c/malloc_size.c Normal file
View File

@@ -0,0 +1,26 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#malloc
*
* Malloc n bytes as given from the command line.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
char *chars;
size_t nbytes;
if (argc < 2) {
nbytes = 2;
} else {
nbytes = strtoull(argv[1], NULL, 0);
}
chars = malloc(nbytes);
if (chars == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
free(chars);
return EXIT_SUCCESS;
}