#include #include #include #include #include typedef struct memory_eating_list_item { struct memory_eating_list_item *prev; void *mem; } memory_eating_list_item; char* fennecProcDir = NULL; void getFennecPID() { DIR *dp; struct dirent *ep; //printf("opening /proc\n"); dp = opendir ("/proc"); if (dp != NULL) { //printf("dp != null\n"); while (ep = readdir (dp)) { char name[256]; sprintf(name, "/proc/%s/cmdline", ep->d_name); //printf("looking in %s\n", name); FILE *procNameFile = fopen(name, "r"); if (procNameFile) { char procName[1024]; fgets(procName, 1024, procNameFile); fclose(procNameFile); if (strstr(procName, "mozilla")) { fennecProcDir = malloc(256); sprintf(fennecProcDir, "/proc/%s", ep->d_name); return; } } } (void) closedir (dp); } else perror ("Couldn't open the directory\n"); } int isFennecRunning() { //printf("%s:%d\n", __PRETTY_FUNCTION__, __LINE__); if (!fennecProcDir) getFennecPID(); if (!fennecProcDir) { printf("couldn't find proc dir\n"); return 0; } FILE* dir = fopen(fennecProcDir, "r"); if (!dir) return 0; fclose(dir); return 1; } int kChunkSize = 1024; int main() { //printf("%s:%d\n", __PRETTY_FUNCTION__, __LINE__); memory_eating_list_item* last = NULL; //printf("%s:%d\n", __PRETTY_FUNCTION__, __LINE__); while (isFennecRunning()) { //printf("%s:%d\n", __PRETTY_FUNCTION__, __LINE__); //printf("Fennec is running\n"); memory_eating_list_item* item = (memory_eating_list_item*) malloc(sizeof(memory_eating_list_item)); if (!item) { printf("we OOM'd ourselvs"); return -1; // we OOM'd ourselves } item->mem = malloc(kChunkSize); if (item->mem) ((char*)item->mem)[0] = 61; else printf("couldn't allocate %d bytes", kChunkSize); item->prev = last; last = item; sched_yield(); } printf("fennec died, cleaning up\n"); while (last) { memory_eating_list_item* prev = last->prev; free(last->mem); free(last); last = prev; } free(fennecProcDir); }