mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2025-01-11 06:45:33 +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
|
// Set the Breakpad symbol information that supplier should return for
|
||||||
// MODULE to INFO.
|
// MODULE to INFO.
|
||||||
void SetModuleSymbols(MockCodeModule *module, const string &info) {
|
void SetModuleSymbols(MockCodeModule *module, const string &info) {
|
||||||
unsigned int buffer_size = info.size() + 1;
|
char *buffer = supplier.CopySymbolDataAndOwnTheCopy(info);
|
||||||
char *buffer = reinterpret_cast<char*>(operator new(buffer_size));
|
|
||||||
strcpy(buffer, info.c_str());
|
|
||||||
EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
|
EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
|
||||||
.WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
|
.WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
|
||||||
Return(MockSymbolSupplier::FOUND)));
|
Return(MockSymbolSupplier::FOUND)));
|
||||||
|
|
|
@ -94,9 +94,7 @@ class StackwalkerARMFixture {
|
||||||
// Set the Breakpad symbol information that supplier should return for
|
// Set the Breakpad symbol information that supplier should return for
|
||||||
// MODULE to INFO.
|
// MODULE to INFO.
|
||||||
void SetModuleSymbols(MockCodeModule *module, const string &info) {
|
void SetModuleSymbols(MockCodeModule *module, const string &info) {
|
||||||
unsigned int buffer_size = info.size() + 1;
|
char *buffer = supplier.CopySymbolDataAndOwnTheCopy(info);
|
||||||
char *buffer = reinterpret_cast<char*>(operator new(buffer_size));
|
|
||||||
strcpy(buffer, info.c_str());
|
|
||||||
EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
|
EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
|
||||||
.WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
|
.WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
|
||||||
Return(MockSymbolSupplier::FOUND)));
|
Return(MockSymbolSupplier::FOUND)));
|
||||||
|
|
|
@ -176,6 +176,29 @@ class MockSymbolSupplier: public google_breakpad::SymbolSupplier {
|
||||||
string *symbol_file,
|
string *symbol_file,
|
||||||
char **symbol_data));
|
char **symbol_data));
|
||||||
MOCK_METHOD1(FreeSymbolData, void(const CodeModule *module));
|
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_
|
#endif // PROCESSOR_STACKWALKER_UNITTEST_UTILS_H_
|
||||||
|
|
|
@ -101,9 +101,7 @@ class StackwalkerX86Fixture {
|
||||||
// Set the Breakpad symbol information that supplier should return for
|
// Set the Breakpad symbol information that supplier should return for
|
||||||
// MODULE to INFO.
|
// MODULE to INFO.
|
||||||
void SetModuleSymbols(MockCodeModule *module, const string &info) {
|
void SetModuleSymbols(MockCodeModule *module, const string &info) {
|
||||||
unsigned int buffer_size = info.size() + 1;
|
char *buffer = supplier.CopySymbolDataAndOwnTheCopy(info);
|
||||||
char *buffer = reinterpret_cast<char*>(operator new(buffer_size));
|
|
||||||
strcpy(buffer, info.c_str());
|
|
||||||
EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
|
EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
|
||||||
.WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
|
.WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
|
||||||
Return(MockSymbolSupplier::FOUND)));
|
Return(MockSymbolSupplier::FOUND)));
|
||||||
|
|
Loading…
Reference in a new issue