From: Loic Dachary Date: Thu, 2 Oct 2014 13:12:30 +0000 (+0200) Subject: perfglue: profiler stats need more than 1024 bytes X-Git-Tag: v0.88~92^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=472a4b32ae3c47513ba8dbea32f9008f9eec358e;p=ceph.git perfglue: profiler stats need more than 1024 bytes 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 --- diff --git a/src/perfglue/heap_profiler.cc b/src/perfglue/heap_profiler.cc index 6b079b865fa9..dd082c63821c 100644 --- a/src/perfglue/heap_profiler.cc +++ b/src/perfglue/heap_profiler.cc @@ -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& cmd, ostream& out) { @@ -93,9 +95,9 @@ void ceph_heap_profiler_handle_command(const std::vector& 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& 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;