]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
perfglue: profiler stats need more than 1024 bytes
authorLoic Dachary <loic-201408@dachary.org>
Thu, 2 Oct 2014 13:12:30 +0000 (15:12 +0200)
committerLoic Dachary <loic-201408@dachary.org>
Wed, 8 Oct 2014 07:47:50 +0000 (09:47 +0200)
With a 1024 bytes buffer to display the stats, the end is truncated.
Use an array on the stack instead of leaking the buffer.

Signed-off-by: Loic Dachary <loic-201408@dachary.org>
src/perfglue/heap_profiler.cc

index 6b079b865fa9c3f24bcf63cf421f805511a0067b..dd082c63821cf65007557b4bdcf4812f30df704a 100644 (file)
@@ -85,6 +85,8 @@ void ceph_heap_profiler_dump(const char *reason)
   HeapProfilerDump(reason);
 }
 
+#define HEAP_PROFILER_STATS_SIZE 2048
+
 void ceph_heap_profiler_handle_command(const std::vector<std::string>& cmd,
                                        ostream& out)
 {
@@ -93,9 +95,9 @@ void ceph_heap_profiler_handle_command(const std::vector<std::string>& cmd,
       out << "heap profiler not running; can't dump";
       return;
     }
-    char *heap_stats = new char[1024];
-    ceph_heap_profiler_stats(heap_stats, 1024);
-    out << g_conf->name << "dumping heap profile now.\n"
+    char heap_stats[HEAP_PROFILER_STATS_SIZE];
+    ceph_heap_profiler_stats(heap_stats, sizeof(heap_stats));
+    out << g_conf->name << " dumping heap profile now.\n"
        << heap_stats;
     ceph_heap_profiler_dump("admin request");
   } else if (cmd.size() == 1 && cmd[0] == "start_profiler") {
@@ -108,9 +110,9 @@ void ceph_heap_profiler_handle_command(const std::vector<std::string>& cmd,
     ceph_heap_release_free_memory();
     out << g_conf->name << " releasing free RAM back to system.";
   } else if (cmd.size() == 1 && cmd[0] == "stats") {
-    char *heap_stats = new char[1024];
-    ceph_heap_profiler_stats(heap_stats, 1024);
-    out << g_conf->name << "tcmalloc heap stats:"
+    char heap_stats[HEAP_PROFILER_STATS_SIZE];
+    ceph_heap_profiler_stats(heap_stats, sizeof(heap_stats));
+    out << g_conf->name << " tcmalloc heap stats:"
        << heap_stats;
   } else {
     out << "unknown command " << cmd;