-
-
Save petabyt/fa20301f0f343a25c075530456a8dca7 to your computer and use it in GitHub Desktop.
autofree.h: Hijack malloc and free on exit(), or autofree()
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
void *allocList_[1000];int allocn_=0;void *malloc_(long unsigned int n){ | |
void *x=malloc(n);allocList_[allocn_]=x;allocn_++;return x;}void autofree(){ | |
while (allocn_){allocn_--;free(allocList_[allocn_]);}} | |
#define malloc(x) malloc_(x) | |
#define exit(x) autofree(x);exit(x); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment