Skip to content

Commit

Permalink
Fixed memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-d committed May 25, 2012
1 parent 3245fef commit ad8709a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions casecorrectpath.cpp
Expand Up @@ -33,11 +33,15 @@ std::string GetCaseCorrectPath(std::string input_path){
char* correct_case_buf = new char[kPathBufferSize];
GetShortPathName(input_path.c_str(), short_path, kPathBufferSize);
GetLongPathName(short_path, correct_case_buf, kPathBufferSize);
std::string corrected = std::string(correct_case_buf);
delete short_path;
return std::string(correct_case_buf);
delete correct_case_buf;
return corrected;
#else // Correct case using realpath() and cut off working directory
std::ptrdiff_t num_dirs = std::count(input_path.begin(), input_path.end(), '/');
std::string path(realpath(input_path.c_str(), NULL));
char* real_path = realpath(input_path.c_str(), NULL);
std::string path(real_path);
free(real_path);
return path.substr(FindNthCharFromBack(path,'/',num_dirs+1)+1);
#endif
}
Expand Down

0 comments on commit ad8709a

Please sign in to comment.