Skip to content

Instantly share code, notes, and snippets.

@martin-ueding
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martin-ueding/a2b79b500c91e590de5e to your computer and use it in GitHub Desktop.
Save martin-ueding/a2b79b500c91e590de5e to your computer and use it in GitHub Desktop.
File descriptor leak test
// Copyright © 2015 Martin Ueding <dev@martin-ueding.de>
// Try to leak as many file descriptors until the program crashes.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
char filename[100];
for (size_t i = 0;; ++i) {
sprintf(filename, "/tmp/%ld.txt", i);
fopen(filename, "w");
if (i % 1000000 == 0) {
printf("%ld\n", i);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment