Skip to content

Instantly share code, notes, and snippets.

@psycho23
Last active April 13, 2017 17:31
Show Gist options
  • Save psycho23/4060353cac8658d9b0d0f150a733674d to your computer and use it in GitHub Desktop.
Save psycho23/4060353cac8658d9b0d0f150a733674d to your computer and use it in GitHub Desktop.
Before you exit ANY C program, you want to first clear all memory so that Mr. Kernel is happy with you.
#include <stdio.h>
#include <limits.h>
int main(void){
/* do your program here, for example: */
int *p_array;
double *d_array;
p_array = (int *)malloc(sizeof(int)*50); // allocate 50 ints
d_array = (int *)malloc(sizeof(double)*100); // allocate 100 doubles
/* now, clear your memory! */
for(int i=0; i<INT_MAX; i++){
try{
free(&i);
}
catch(SegmentationFaultException _sfex){}
}
/* SUCCESS! */
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment