mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2024-12-23 08:55:27 +00:00
Fixing a mem leak in test code
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@975 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
parent
6de969a304
commit
1a7a0a4d4b
|
@ -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)));
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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)));
|
||||
|
|
Loading…
Reference in a new issue