我是 c++初学者,尝试使用多进程时遇到了诡异的内存泄漏的问题,这是全部代码。
在我本地的服务器用 valgrind 测试没有泄漏,但另一台服务器上就会出现泄漏问题,我百思不得其解,请大神给点思路
随附 cpp 源文件和 valgrind 的 log 的下载链接:
#include <string.h> #include <regex> #include <sys/wait.h> #include <unistd.h>int test(std::string input, std::string output){ int status = 0;
pid_t pid; for (int i = 0; i < 10; i++) { pid = fork(); if (pid == 0) { exit(0); } else if (pid < 0) { perror("fork"); exit(1); } else { waitpid(pid, &status, 0); } } // memery leak return 0;}
int main(int argc, char *argv[]) { std::string input = "1"; std::string output = "2";
test(input, output); return 0;}