mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2025-09-04 12:41:01 +00:00
Fix memory leak when using the basic source line resolver, plus the optimization to load using in-memory buffers. Moved from manually allocating/deallocating memory to using a scoped_array
A=nealsid R=tiger feng git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@329 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
parent
a0a0de39a8
commit
ad6543e4e7
|
@ -278,20 +278,28 @@ bool BasicSourceLineResolver::Module::LoadMapFromBuffer(
|
||||||
// have to copy because modifying the result of string::c_str is not
|
// have to copy because modifying the result of string::c_str is not
|
||||||
// permitted
|
// permitted
|
||||||
size_t map_buffer_length = strlen(map_buffer_c_str);
|
size_t map_buffer_length = strlen(map_buffer_c_str);
|
||||||
char *map_buffer_chars = new char[map_buffer_length];
|
|
||||||
|
// If the length is 0, we can still pretend we have a symbol file. This is
|
||||||
|
// for scenarios that want to test symbol lookup, but don't necessarily care if
|
||||||
|
// certain modules do not have any information, like system libraries.
|
||||||
|
if (map_buffer_length == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
scoped_array<char> map_buffer_chars(new char[map_buffer_length]);
|
||||||
if (map_buffer_chars == NULL) {
|
if (map_buffer_chars == NULL) {
|
||||||
BPLOG(ERROR) << "Memory allocation of " << map_buffer_length <<
|
BPLOG(ERROR) << "Memory allocation of " << map_buffer_length <<
|
||||||
" bytes failed";
|
" bytes failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(map_buffer_chars, map_buffer_c_str, map_buffer_length);
|
strncpy(map_buffer_chars.get(), map_buffer_c_str, map_buffer_length);
|
||||||
|
|
||||||
if (map_buffer_chars[map_buffer_length - 1] == '\n') {
|
if (map_buffer_chars[map_buffer_length - 1] == '\n') {
|
||||||
map_buffer_chars[map_buffer_length - 1] = '\0';
|
map_buffer_chars[map_buffer_length - 1] = '\0';
|
||||||
}
|
}
|
||||||
char *buffer;
|
char *buffer;
|
||||||
buffer = strtok_r(map_buffer_chars, "\r\n", &save_ptr);
|
buffer = strtok_r(map_buffer_chars.get(), "\r\n", &save_ptr);
|
||||||
|
|
||||||
while (buffer != NULL) {
|
while (buffer != NULL) {
|
||||||
++line_number;
|
++line_number;
|
||||||
|
@ -300,14 +308,12 @@ bool BasicSourceLineResolver::Module::LoadMapFromBuffer(
|
||||||
if (!ParseFile(buffer)) {
|
if (!ParseFile(buffer)) {
|
||||||
BPLOG(ERROR) << "ParseFile on buffer failed at " <<
|
BPLOG(ERROR) << "ParseFile on buffer failed at " <<
|
||||||
":" << line_number;
|
":" << line_number;
|
||||||
delete [] map_buffer_chars;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (strncmp(buffer, "STACK ", 6) == 0) {
|
} else if (strncmp(buffer, "STACK ", 6) == 0) {
|
||||||
if (!ParseStackInfo(buffer)) {
|
if (!ParseStackInfo(buffer)) {
|
||||||
BPLOG(ERROR) << "ParseStackInfo failed at " <<
|
BPLOG(ERROR) << "ParseStackInfo failed at " <<
|
||||||
":" << line_number;
|
":" << line_number;
|
||||||
delete [] map_buffer_chars;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (strncmp(buffer, "FUNC ", 5) == 0) {
|
} else if (strncmp(buffer, "FUNC ", 5) == 0) {
|
||||||
|
@ -315,7 +321,6 @@ bool BasicSourceLineResolver::Module::LoadMapFromBuffer(
|
||||||
if (!cur_func.get()) {
|
if (!cur_func.get()) {
|
||||||
BPLOG(ERROR) << "ParseFunction failed at " <<
|
BPLOG(ERROR) << "ParseFunction failed at " <<
|
||||||
":" << line_number;
|
":" << line_number;
|
||||||
delete [] map_buffer_chars;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// StoreRange will fail if the function has an invalid address or size.
|
// StoreRange will fail if the function has an invalid address or size.
|
||||||
|
@ -329,7 +334,6 @@ bool BasicSourceLineResolver::Module::LoadMapFromBuffer(
|
||||||
if (!ParsePublicSymbol(buffer)) {
|
if (!ParsePublicSymbol(buffer)) {
|
||||||
BPLOG(ERROR) << "ParsePublicSymbol failed at " <<
|
BPLOG(ERROR) << "ParsePublicSymbol failed at " <<
|
||||||
":" << line_number;
|
":" << line_number;
|
||||||
delete [] map_buffer_chars;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (strncmp(buffer, "MODULE ", 7) == 0) {
|
} else if (strncmp(buffer, "MODULE ", 7) == 0) {
|
||||||
|
@ -343,14 +347,12 @@ bool BasicSourceLineResolver::Module::LoadMapFromBuffer(
|
||||||
if (!cur_func.get()) {
|
if (!cur_func.get()) {
|
||||||
BPLOG(ERROR) << "Found source line data without a function at " <<
|
BPLOG(ERROR) << "Found source line data without a function at " <<
|
||||||
":" << line_number;
|
":" << line_number;
|
||||||
delete [] map_buffer_chars;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Line *line = ParseLine(buffer);
|
Line *line = ParseLine(buffer);
|
||||||
if (!line) {
|
if (!line) {
|
||||||
BPLOG(ERROR) << "ParseLine failed at " << line_number << " for " <<
|
BPLOG(ERROR) << "ParseLine failed at " << line_number << " for " <<
|
||||||
buffer;
|
buffer;
|
||||||
delete [] map_buffer_chars;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cur_func->lines.StoreRange(line->address, line->size,
|
cur_func->lines.StoreRange(line->address, line->size,
|
||||||
|
|
Loading…
Reference in a new issue