1/* Test for memory/CPU leak in regcomp.  */
2
3#ifdef HAVE_CONFIG_H
4#include "config.h"
5#endif
6
7#include <sys/types.h>
8#include <sys/time.h>
9#include <sys/resource.h>
10#include <regex.h>
11#include <stdio.h>
12#include <stdlib.h>
13
14#define TEST_DATA_LIMIT (32 << 20)
15
16int
17main ()
18{
19#ifdef RLIMIT_DATA
20  regex_t re;
21  int reerr;
22
23  /* Try to avoid eating all memory if a test leaks.  */
24  struct rlimit data_limit;
25  if (getrlimit (RLIMIT_DATA, &data_limit) == 0)
26    {
27      if ((rlim_t) TEST_DATA_LIMIT > data_limit.rlim_max)
28	data_limit.rlim_cur = data_limit.rlim_max;
29      else if (data_limit.rlim_cur > (rlim_t) TEST_DATA_LIMIT)
30	data_limit.rlim_cur = (rlim_t) TEST_DATA_LIMIT;
31      if (setrlimit (RLIMIT_DATA, &data_limit) < 0)
32	perror ("setrlimit: RLIMIT_DATA");
33    }
34  else
35    perror ("getrlimit: RLIMIT_DATA");
36
37  reerr = regcomp (&re, "^6?3?[25]?5?[14]*[25]*[69]*+[58]*87?4?$",
38		   REG_EXTENDED | REG_NOSUB);
39  if (reerr != 0)
40    {
41      char buf[100];
42      regerror (reerr, &re, buf, sizeof buf);
43      printf ("regerror %s\n", buf);
44      return 1;
45    }
46
47  return 0;
48#else
49  return 77;
50#endif
51}
52