potential-memleaks.c 821 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define FGETS_BUFSIZE 64
  5. /* Problem with FreeBSD 10.3 fgets() with stdin. */
  6. static void
  7. pl_freebsd_fgets()
  8. {
  9. char buf[FGETS_BUFSIZE];
  10. if (fgets(buf, FGETS_BUFSIZE, stdin) == NULL)
  11. exit(1);
  12. }
  13. #define MEMLEAKTEST(x) { #x, x }
  14. static const struct memleaktest {
  15. const char * name;
  16. void (* func)(void);
  17. } tests[] = {
  18. MEMLEAKTEST(pl_freebsd_fgets)
  19. };
  20. static const int num_tests = sizeof(tests) / sizeof(tests[0]);
  21. int
  22. main(int argc, char * argv[])
  23. {
  24. int i;
  25. if (argc == 2) {
  26. /* Run the relevant function. */
  27. for (i = 0; i < num_tests; i++) {
  28. if ((strcmp(argv[1], tests[i].name)) == 0)
  29. tests[i].func();
  30. }
  31. } else {
  32. /* Print test names. */
  33. for (i = 0; i < num_tests; i++)
  34. printf("%s\n", tests[i].name);
  35. }
  36. /* Success! */
  37. exit(0);
  38. }