Created
May 2, 2013 01:49
-
-
Save wjlafrance/5499678 to your computer and use it in GitHub Desktop.
Does your compiler clean up after you?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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