Skip to content

Instantly share code, notes, and snippets.

@jnguyen1098
Created March 30, 2021 09:05
Show Gist options
  • Save jnguyen1098/79e55aaa4b9006d9c409ebd852a99ce7 to your computer and use it in GitHub Desktop.
Save jnguyen1098/79e55aaa4b9006d9c409ebd852a99ce7 to your computer and use it in GitHub Desktop.
goodbye valgrind leaks xd
#include <stdlib.h>
char *ram;
size_t brk;
void __attribute__((constructor)) lmao(void) {
!ram ? atexit(lmao), ram = calloc(1, 100000) : free(ram);
}
#define calloc(x,y)(malloc(x*y))
#define malloc(x)(void *)(&ram[brk] + x >= &ram[100000 - 1] ? NULL : (brk += x, &ram[brk - x]))
#define free(x)
#include <stdlib.h>
void *ptr, *addrs[100000];
size_t head;
__attribute__((destructor)) static inline void cleanup() {
for (size_t i = 0; i < head; i++)
addrs[i] = (free(addrs[i]), NULL);
}
#define free(x) if(x){}
#define malloc(x)(addrs[head++]=malloc(x))
#define calloc(x,y)(addrs[head++]=calloc(x,y))
#define realloc(x,y)((x?__extension__({ptr=x;for(size_t i=0;i<head;i++)addrs[i]==ptr?addrs[i]=0:0;}):(void)0),addrs[head++]=realloc(x,y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment