trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sor...@apache.org
Subject trafficserver git commit: TS-3287: Fix resource leak in config
Date Thu, 05 Feb 2015 02:13:34 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master 2c2a5155c -> 9fbc03104


TS-3287: Fix resource leak in config

Coverity CID #1268095


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/9fbc0310
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/9fbc0310
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/9fbc0310

Branch: refs/heads/master
Commit: 9fbc03104f6dbe51c4f4e910b2928e856fec258f
Parents: 2c2a515
Author: Phil Sorber <sorber@apache.org>
Authored: Wed Feb 4 19:12:43 2015 -0700
Committer: Phil Sorber <sorber@apache.org>
Committed: Wed Feb 4 19:12:43 2015 -0700

----------------------------------------------------------------------
 plugins/experimental/url_sig/url_sig.c | 33 ++++++++++++++++-------------
 1 file changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9fbc0310/plugins/experimental/url_sig/url_sig.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/url_sig/url_sig.c b/plugins/experimental/url_sig/url_sig.c
index bd24987..8e7af49 100644
--- a/plugins/experimental/url_sig/url_sig.c
+++ b/plugins/experimental/url_sig/url_sig.c
@@ -38,13 +38,19 @@ static const char *PLUGIN_NAME = "url_sig";
 
 struct config
 {
-  char *map_from;
-  char *map_to;
   TSHttpStatus err_status;
   char *err_url;
   char keys[MAX_KEY_NUM][MAX_KEY_LEN];
 };
 
+void
+free_cfg(struct config *cfg)
+{
+  TSError("Cleaning up...");
+  TSfree(cfg->err_url);
+  TSfree(cfg);
+}
+
 TSReturnCode
 TSRemapInit(TSRemapInterface * api_info, char *errbuf, int errbuf_size)
 {
@@ -70,9 +76,6 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
   char config_file[PATH_MAX];
   struct config *cfg;
 
-  cfg = TSmalloc(sizeof(struct config));
-  memset(cfg, 0, sizeof(struct config));
-
   if (argc != 3) {
     snprintf(errbuf, errbuf_size - 1,
              "[TSRemapNewKeyInstance] - Argument count wrong (%d)... Need exactly two pparam=
(config file name).",
@@ -80,8 +83,6 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
     return TS_ERROR;
   }
   TSDebug(PLUGIN_NAME, "Initializing remap function of %s -> %s with config from %s",
argv[0], argv[1], argv[2]);
-  cfg->map_from = TSstrndup(argv[0], strlen(argv[0]));
-  cfg->map_to = TSstrndup(argv[0], strlen(argv[1]));
 
   const char *install_dir = TSInstallDirGet();
   snprintf(config_file, sizeof(config_file), "%s/%s/%s", install_dir, "etc/trafficserver",
argv[2]);
@@ -95,6 +96,10 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
   char line[260];
   int line_no = 0;
   int keynum;
+
+  cfg = TSmalloc(sizeof(struct config));
+  memset(cfg, 0, sizeof(struct config));
+
   while (fgets(line, sizeof(line), file) != NULL) {
     TSDebug(PLUGIN_NAME, "LINE: %s (%d)", line, (int) strlen(line));
     line_no++;
@@ -116,6 +121,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
       snprintf(errbuf, errbuf_size - 1, "[TSRemapNewInstance] - Maximum line (%d) exceeded
on line %d.", MAX_KEY_LEN,
                line_no);
       fclose(file);
+      free_cfg(cfg);
       return TS_ERROR;
     }
     if (strncmp(line, "key", 3) == 0) {
@@ -133,6 +139,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
         snprintf(errbuf, errbuf_size - 1, "[TSRemapNewInstance] - Key number (%d) > MAX_KEY_NUM
(%d) or NaN.", keynum,
                  MAX_KEY_NUM);
         fclose(file);
+        free_cfg(cfg);
         return TS_ERROR;
       }
       strcpy(&cfg->keys[keynum][0], value);
@@ -163,6 +170,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
       snprintf(errbuf, errbuf_size - 1,
                "[TSRemapNewInstance] - Invalid config, err_status == 302, but err_url ==
NULL");
       fclose(file);
+      free_cfg(cfg);
       return TS_ERROR;
     }
     break;
@@ -171,12 +179,14 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf,
int errbuf_s
       snprintf(errbuf, errbuf_size - 1,
                "[TSRemapNewInstance] - Invalid config, err_status == 403, but err_url !=
NULL");
       fclose(file);
+      free_cfg(cfg);
       return TS_ERROR;
     }
     break;
   default:
     snprintf(errbuf, errbuf_size - 1, "[TSRemapNewInstance] - Return code %d not supported.",
cfg->err_status);
     fclose(file);
+    free_cfg(cfg);
     return TS_ERROR;
 
   }
@@ -190,14 +200,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
 void
 TSRemapDeleteInstance(void *ih)
 {
-  struct config *cfg;
-  cfg = (struct config *) ih;
-
-  TSError("Cleaning up...");
-  TSfree(cfg->map_from);
-  TSfree(cfg->map_to);
-  TSfree(cfg->err_url);
-  TSfree(cfg);
+  free_cfg((struct config *)ih);
 }
 
 void


Mime
View raw message