Permalink
Browse files

Fixed memory leaks

  • Loading branch information...
1 parent 3245fef commit ad8709afe6c2dda59e675087a1e97de08e26e481 @andre-d committed May 25, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 casecorrectpath.cpp
View
8 casecorrectpath.cpp
@@ -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
}

0 comments on commit ad8709a

Please sign in to comment.