fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5.  
  6. long long int petabyte = 1024LL * 1024LL * 1024LL * 1024LL * 1024LL; // 10^15
  7. printf("petabyte %lld \n", petabyte);
  8.  
  9. volatile char *ptr = (volatile char *)malloc(petabyte);
  10. printf("malloc() - success, ptr = %p \n", ptr);
  11.  
  12. ptr[petabyte - 1LL] = 10;
  13. printf("ptr[petabyte - 1] = 10; - success \n");
  14.  
  15. printf("ptr[petabyte - 1] = %d \n", (int)(ptr[petabyte - 1LL]));
  16.  
  17. free((void*)ptr); // why the error is here?
  18. //printf("free() - success \n");
  19.  
  20. return 0;
  21. }
  22.  
Runtime error #stdin #stdout #stderr 0s 2292KB
stdin
Standard input is empty
stdout
petabyte 1125899906842624 
malloc() - success, ptr = 0x823e008 
ptr[petabyte - 1] = 10; - success 
ptr[petabyte - 1] = 10 
stderr
*** Error in `./prog': double free or corruption (out): 0x0823e008 ***