Skip to content

Commit 58edc85

Browse files
authored
Merge pull request #52 from gburgessiv/master
Fix path truncation in profile_creator
2 parents 153c178 + 39d436b commit 58edc85

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

profile_creator.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,17 @@ bool ProfileCreator::CreateProfile(const string &input_profile_name,
5454
bool ProfileCreator::ReadSample(const string &input_profile_name,
5555
const string &profiler) {
5656
if (profiler == "perf") {
57-
// Sets the regular expression to filter samples for a given binary.
58-
char *dup_name = strdup(binary_.c_str());
59-
char *strip_ptr = strstr(dup_name, ".unstripped");
60-
if (strip_ptr) {
61-
*strip_ptr = 0;
57+
string file_base_name = basename(binary_.c_str());
58+
size_t unstripped_at = file_base_name.find(".unstripped");
59+
if (unstripped_at != string::npos) {
60+
file_base_name.erase(unstripped_at);
6261
}
63-
const char *file_base_name = basename(dup_name);
64-
CHECK(file_base_name) << "Cannot find basename for: " << binary_;
62+
CHECK(!file_base_name.empty()) << "Cannot find basename for: " << binary_;
6563

6664
ElfReader reader(binary_);
6765

6866
sample_reader_ = new PerfDataSampleReader(
69-
input_profile_name, file_base_name);
70-
free(dup_name);
67+
input_profile_name, std::move(file_base_name));
7168
} else if (profiler == "text") {
7269
sample_reader_ = new TextSampleReaderWriter(input_profile_name);
7370
} else {

0 commit comments

Comments
 (0)