aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/processor/stackwalker_amd64_unittest.cc4
-rw-r--r--src/processor/stackwalker_arm_unittest.cc4
-rw-r--r--src/processor/stackwalker_unittest_utils.h23
-rw-r--r--src/processor/stackwalker_x86_unittest.cc4
4 files changed, 26 insertions, 9 deletions
diff --git a/src/processor/stackwalker_amd64_unittest.cc b/src/processor/stackwalker_amd64_unittest.cc
index 26c1a26f..f3723c0c 100644
--- a/src/processor/stackwalker_amd64_unittest.cc
+++ b/src/processor/stackwalker_amd64_unittest.cc
@@ -92,9 +92,7 @@ class StackwalkerAMD64Fixture {
// Set the Breakpad symbol information that supplier should return for
// MODULE to INFO.
void SetModuleSymbols(MockCodeModule *module, const string &info) {
- unsigned int buffer_size = info.size() + 1;
- char *buffer = reinterpret_cast<char*>(operator new(buffer_size));
- strcpy(buffer, info.c_str());
+ char *buffer = supplier.CopySymbolDataAndOwnTheCopy(info);
EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
.WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
Return(MockSymbolSupplier::FOUND)));
diff --git a/src/processor/stackwalker_arm_unittest.cc b/src/processor/stackwalker_arm_unittest.cc
index 3925dcd8..10772ba4 100644
--- a/src/processor/stackwalker_arm_unittest.cc
+++ b/src/processor/stackwalker_arm_unittest.cc
@@ -94,9 +94,7 @@ class StackwalkerARMFixture {
// Set the Breakpad symbol information that supplier should return for
// MODULE to INFO.
void SetModuleSymbols(MockCodeModule *module, const string &info) {
- unsigned int buffer_size = info.size() + 1;
- char *buffer = reinterpret_cast<char*>(operator new(buffer_size));
- strcpy(buffer, info.c_str());
+ char *buffer = supplier.CopySymbolDataAndOwnTheCopy(info);
EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
.WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
Return(MockSymbolSupplier::FOUND)));
diff --git a/src/processor/stackwalker_unittest_utils.h b/src/processor/stackwalker_unittest_utils.h
index 551d3191..5257f816 100644
--- a/src/processor/stackwalker_unittest_utils.h
+++ b/src/processor/stackwalker_unittest_utils.h
@@ -176,6 +176,29 @@ class MockSymbolSupplier: public google_breakpad::SymbolSupplier {
string *symbol_file,
char **symbol_data));
MOCK_METHOD1(FreeSymbolData, void(const CodeModule *module));
+
+ // Copies the passed string contents into a newly allocated buffer.
+ // The newly allocated buffer will be freed during destruction.
+ char* CopySymbolDataAndOwnTheCopy(const std::string &info) {
+ unsigned int buffer_size = info.size() + 1;
+ char *symbol_data = new char [buffer_size];
+ strcpy(symbol_data, info.c_str());
+ symbol_data_to_free_.push_back(symbol_data);
+ return symbol_data;
+ }
+
+ virtual ~MockSymbolSupplier() {
+ for (SymbolDataVector::const_iterator i = symbol_data_to_free_.begin();
+ i != symbol_data_to_free_.end(); i++) {
+ char* symbol_data = *i;
+ delete [] symbol_data;
+ }
+ }
+
+ private:
+ // List of symbol data to be freed upon destruction
+ typedef std::vector<char*> SymbolDataVector;
+ SymbolDataVector symbol_data_to_free_;
};
#endif // PROCESSOR_STACKWALKER_UNITTEST_UTILS_H_
diff --git a/src/processor/stackwalker_x86_unittest.cc b/src/processor/stackwalker_x86_unittest.cc
index 58dfb6be..08e2a6eb 100644
--- a/src/processor/stackwalker_x86_unittest.cc
+++ b/src/processor/stackwalker_x86_unittest.cc
@@ -101,9 +101,7 @@ class StackwalkerX86Fixture {
// Set the Breakpad symbol information that supplier should return for
// MODULE to INFO.
void SetModuleSymbols(MockCodeModule *module, const string &info) {
- unsigned int buffer_size = info.size() + 1;
- char *buffer = reinterpret_cast<char*>(operator new(buffer_size));
- strcpy(buffer, info.c_str());
+ char *buffer = supplier.CopySymbolDataAndOwnTheCopy(info);
EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
.WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
Return(MockSymbolSupplier::FOUND)));