Files
linux-kernel-module-cheat/userland/c/malloc.c
Ciro Santilli 六四事件 法轮功 d7a24ea200 start moving malloc and friends in
2019-08-11 00:00:00 +00:00

23 lines
503 B
C

/* https://cirosantilli.com/linux-kernel-module-cheat#malloc */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
size_t bytes = sizeof(int) * 2;
/* Allocate 2 ints. */
int *is = malloc(bytes);
/* This can happen for example if we ask for too much memory. */
if (is == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
is[0] = 1;
assert(is[0] == 1);
/* Free the allocated memory. */
free(is);
return EXIT_SUCCESS;
}