Files
linux-kernel-module-cheat/userland/c/malloc_size.c
Ciro Santilli 六四事件 法轮功 efc4205416 Become a memory accounting amateur
2019-08-27 00:00:00 +00:00

27 lines
511 B
C

/* 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;
}