Skip to content

Commit

Permalink
memory leak issue (#172)
Browse files Browse the repository at this point in the history
* remove std::string wrapper and final nullptr setting

* * Memory leak issue
Failing to save or free storage allocated from
rcutils_join_path(), which results in memory leak

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>

* add back the necessary std::string for file_path and
reorganize the code to make it more clear

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>

* optimize variable scope and string converting

* Make file_prefix a std::string

Also remove the error messages, since in the no-enforce case,
we don't want random error messages to appear.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
  • Loading branch information
gaoethan authored and clalancette committed Nov 7, 2017
1 parent 71c69ac commit 425914d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions rmw_fastrtps_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,24 @@ get_security_file_paths(
const char * file_names[3] = {"ca.cert.pem", "cert.pem", "key.pem"};
size_t num_files = sizeof(file_names) / sizeof(char *);

const char * file_prefix = "file://";
std::string file_prefix("file://");

std::string tmpstr;
for (size_t i = 0; i < num_files; i++) {
tmpstr = std::string(rcutils_join_path(node_secure_root, file_names[i]));
if (!rcutils_is_readable(tmpstr.c_str())) {
const char * file_path = rcutils_join_path(node_secure_root, file_names[i]);
if (!file_path) {
return false;
}
security_files_paths[i] = std::string(file_prefix + tmpstr);

if (rcutils_is_readable(file_path)) {
security_files_paths[i] = file_prefix + std::string(file_path);
} else {
free(const_cast<char *>(file_path));
return false;
}

free(const_cast<char *>(file_path));
}

return true;
}

Expand Down

0 comments on commit 425914d

Please sign in to comment.