]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
start_profiler/enable_profiler_options:fix memleak
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 4 Nov 2010 21:26:08 +0000 (14:26 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 4 Nov 2010 21:26:08 +0000 (14:26 -0700)
Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/mds/MDS.cc
src/osd/OSD.cc

index 2c6cde34cdac00bca1225327b192fa939d567567..9550cde72dc13a46f29d337a87eac6ccbe067bdc 100644 (file)
@@ -750,17 +750,20 @@ void MDS::handle_command(MMonCommand *m)
     }
     logclient.log(LOG_INFO, ss);
   } else if (m->cmd.size() == 1 && m->cmd[0] == "enable_profiler_options") {
-    char *val = new char[sizeof(int)*8+1];
-    sprintf(val, "%i", g_conf.profiler_allocation_interval);
-    setenv("HEAP_PROFILE_ALLOCATION_INTERVAL", val, g_conf.profiler_allocation_interval);
-    sprintf(val, "%i", g_conf.profiler_highwater_interval);
-    setenv("HEAP_PROFILE_INUSE_INTERVAL", val, g_conf.profiler_highwater_interval);
+    char val[sizeof(int)*8+1];
+    snprintf(val, sizeof(val), "%i", g_conf.profiler_allocation_interval);
+    setenv("HEAP_PROFILE_ALLOCATION_INTERVAL",
+          val, g_conf.profiler_allocation_interval);
+    snprintf(val, sizeof(val), "%i", g_conf.profiler_highwater_interval);
+    setenv("HEAP_PROFILE_INUSE_INTERVAL",
+          val, g_conf.profiler_highwater_interval);
     stringstream ss;
     ss << g_conf.name << " set heap variables from current config";
     logclient.log(LOG_INFO, ss);
   } else if (m->cmd.size() == 1 && m->cmd[0] == "start_profiler") {
-    char *location = new char[PATH_MAX];
-    sprintf(location, "%s/%s", g_conf.log_dir, g_conf.name);
+    char location[PATH_MAX];
+    snprintf(location, sizeof(location),
+            "%s/%s", g_conf.log_dir, g_conf.name);
     g_conf.profiler_start(location);
     stringstream ss;
     ss << g_conf.name << " started profiler";
index 122931af14cce2b6b90f35ffcc2f151f520f1aaa..7048d0bf4114b29b55100a7887b067c78f59e724 100644 (file)
@@ -1832,17 +1832,18 @@ void OSD::handle_command(MMonCommand *m)
     }
     logclient.log(LOG_INFO, ss);
   } else if (m->cmd.size() == 1 && m->cmd[0] == "enable_profiler_options") {
-    char *val = new char[sizeof(int)*8+1];
-    sprintf(val, "%i", g_conf.profiler_allocation_interval);
+    char val[sizeof(int)*8+1];
+    snprintf(val, sizeof(val), "%i", g_conf.profiler_allocation_interval);
     setenv("HEAP_PROFILE_ALLOCATION_INTERVAL", val, g_conf.profiler_allocation_interval);
-    sprintf(val, "%i", g_conf.profiler_highwater_interval);
+    snprintf(val, sizeof(val), "%i", g_conf.profiler_highwater_interval);
     setenv("HEAP_PROFILE_INUSE_INTERVAL", val, g_conf.profiler_highwater_interval);
     stringstream ss;
     ss << g_conf.name << " set heap variables from current config";
     logclient.log(LOG_INFO, ss);
   } else if (m->cmd.size() == 1 && m->cmd[0] == "start_profiler") {
-    char *location = new char[PATH_MAX];
-    sprintf(location, "%s/%s", g_conf.log_dir, g_conf.name);
+    char location[PATH_MAX];
+    snprintf(location, sizeof(location),
+            "%s/%s", g_conf.log_dir, g_conf.name);
     g_conf.profiler_start(location);
     stringstream ss;
     ss << g_conf.name << " started profiler with output " << location;