summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn van der Kamp <john@kirika.demon.nl>2010-06-01 07:54:25 +0530
committerMukund Sivaraman <muks@banu.com>2010-06-01 07:54:55 +0530
commita7933bdd3646d6be114eb5c68093918997840d9b (patch)
tree96f50f716897aa3eb1a0725932566de1e0ce107c /src
parent50e3a0f6d97e0a2d2d797b3766939171747fea2d (diff)
downloadtinyproxy-a7933bdd3646d6be114eb5c68093918997840d9b.tar.gz
tinyproxy-a7933bdd3646d6be114eb5c68093918997840d9b.zip
[BB#89] Don't recompile regular expressions
This is a modification of a patch originally written by John van der Kamp <john@kirika.demon.nl> at <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579427#12> The modification was done by the committer.
Diffstat (limited to 'src')
-rw-r--r--src/conf.c28
-rw-r--r--src/conf.h2
-rw-r--r--src/main.c5
3 files changed, 33 insertions, 2 deletions
diff --git a/src/conf.c b/src/conf.c
index c089fc7..269941e 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -163,6 +163,8 @@ static HANDLE_FUNC (handle_upstream);
static HANDLE_FUNC (handle_upstream_no);
#endif
+static void config_free_regex (void);
+
/*
* This macro can be used to make standard directives in the form:
* directive arguments [arguments ...]
@@ -317,7 +319,8 @@ static void free_config (struct config_s *conf)
*
* Returns 0 on success; negative upon failure.
*/
-static int config_compile (void)
+int
+config_compile_regex (void)
{
unsigned int i, r;
@@ -335,10 +338,31 @@ static int config_compile (void)
if (r)
return r;
}
+
+ atexit (config_free_regex);
+
return 0;
}
/*
+ * Frees pre-compiled regular expressions used by the configuration
+ * file. This function is registered to be automatically called at exit.
+ */
+static void
+config_free_regex (void)
+{
+ unsigned int i;
+
+ for (i = 0; i < ndirectives; i++) {
+ if (directives[i].cre) {
+ regfree (directives[i].cre);
+ safefree (directives[i].cre);
+ directives[i].cre = NULL;
+ }
+ }
+}
+
+/*
* Attempt to match the supplied line with any of the configuration
* regexes defined above. If a match is found, call the handler
* function to process the directive.
@@ -397,7 +421,7 @@ static int load_config_file (const char *config_fname, struct config_s *conf)
goto done;
}
- if (config_compile () || config_parse (conf, config_file)) {
+ if (config_parse (conf, config_file)) {
fprintf (stderr, "Unable to parse config file. "
"Not starting.\n");
goto done;
diff --git a/src/conf.h b/src/conf.h
index 9a53adf..f62a854 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -115,4 +115,6 @@ struct config_s {
extern int reload_config_file (const char *config_fname, struct config_s *conf,
struct config_s *defaults);
+int config_compile_regex (void);
+
#endif
diff --git a/src/main.c b/src/main.c
index 064b440..228b381 100644
--- a/src/main.c
+++ b/src/main.c
@@ -383,6 +383,11 @@ main (int argc, char **argv)
log_message (LOG_INFO, "Initializing " PACKAGE " ...");
+ ret = config_compile_regex();
+ if (ret != 0) {
+ exit (EX_SOFTWARE);
+ }
+
initialize_config_defaults (&config_defaults);
process_cmdline (argc, argv, &config_defaults);