From 472a4b32ae3c47513ba8dbea32f9008f9eec358e Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Thu, 2 Oct 2014 15:12:30 +0200 Subject: [PATCH] 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 --- src/perfglue/heap_profiler.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/perfglue/heap_profiler.cc b/src/perfglue/heap_profiler.cc index 6b079b865fa9c..dd082c63821cf 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; -- 2.39.5