mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
Become a memory accounting amateur
This commit is contained in:
26
userland/c/malloc_size.c
Normal file
26
userland/c/malloc_size.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user