fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void memoryLeak() {
  5. int *ptr = (int*)malloc(sizeof(int));
  6. *ptr = 10;
  7. // Missing free(ptr); statement, causing a memory leak
  8. }
  9.  
  10. int main() {
  11. for (int i = 0; i < 1000000; i++) {
  12. memoryLeak(); // Repeatedly calling the function with the memory leak
  13. }
  14. printf("Finished allocating memory (with leaks)!\n");
  15. return 0;
  16. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Finished allocating memory (with leaks)!