Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created May 2, 2013 01:49
Show Gist options
  • Save wjlafrance/5499678 to your computer and use it in GitHub Desktop.
Save wjlafrance/5499678 to your computer and use it in GitHub Desktop.
Does your compiler clean up after you?
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
void heapTest() {
int heapsize = 1024 * 1024; // 1MB
uint8_t *data = malloc(heapsize);
for (int i = 0; i < heapsize; i++) {
if (data[i] != 0) {
printf("unclean heap\n");
goto cleanup;
}
}
printf("clean heap\n");
cleanup: free(data);
}
void stackTest() {
uint64_t int1;
uint64_t int2;
uint64_t int3;
uint64_t int4;
if (int1 == 0 && int2 == 0 && int3 == 0 && int4 == 0) {
printf("clean stack\n");
} else {
printf("dirty stack\n");
}
}
int main(int argc, char** argv) {
heapTest();
stackTest();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment