diff --git a/util/process_map.cpp b/util/process_map.cpp index 9875e016f143d9f2aae1a7f28379d62880277203..538617cf03d53208534b86c6792e31e6b44b3974 100644 --- a/util/process_map.cpp +++ b/util/process_map.cpp @@ -166,9 +166,9 @@ void StoreThreadId(int** childTidList, int* count, const char* entryName) } } -bool GetChildTidRecursive(const char *dirPath, int **childTidList, int *count) +bool GetChildTidRecursive(const std::string& dirPath, int **childTidList, int *count) { - DIR *dir = opendir(dirPath); + DIR *dir = opendir(dirPath.c_str()); if (!dir) { return false; } @@ -186,14 +186,6 @@ bool GetChildTidRecursive(const char *dirPath, int **childTidList, int *count) // Store the thread ID in the array StoreThreadId(childTidList, count, entry->d_name); } - - char path[PATH_LEN]; - if (snprintf(path, sizeof(path), "%s/%s", dirPath, entry->d_name) < 0) { - continue; - } - - // Continue recursively - GetChildTidRecursive(path, childTidList, count); } } @@ -210,10 +202,7 @@ int *GetChildTid(int pid, int *numChild) *numChild = 1; return childTidList; } - char dirPath[PATH_LEN]; - if (snprintf(dirPath, sizeof(dirPath), "/proc/%d/task", pid) < 0) { - return nullptr; - } + std::string dirPath = "/proc/" + std::to_string(pid) + "/task"; *numChild = 0; if (!GetChildTidRecursive(dirPath, &childTidList, numChild)) { if (childTidList) { @@ -223,5 +212,4 @@ int *GetChildTid(int pid, int *numChild) *numChild = 0; } return childTidList; -} - +} \ No newline at end of file