diff --git a/src/mongo/util/processinfo_linux.cpp b/src/mongo/util/processinfo_linux.cpp index dee779cb1b662..13608c296a7c8 100644 --- a/src/mongo/util/processinfo_linux.cpp +++ b/src/mongo/util/processinfo_linux.cpp @@ -496,6 +496,8 @@ class LinuxSysHelper { if (f != nullptr) { if (fgets(fstr, 1023, f) != nullptr) fstr[strlen(fstr) < 1 ? 0 : strlen(fstr) - 1] = '\0'; + else + fstr[0] = '\0'; fclose(f); } return fstr; diff --git a/src/third_party/tcmalloc/dist/tcmalloc/cpu_cache.cc b/src/third_party/tcmalloc/dist/tcmalloc/cpu_cache.cc index e8006815c1763..8e4f600a62b74 100644 --- a/src/third_party/tcmalloc/dist/tcmalloc/cpu_cache.cc +++ b/src/third_party/tcmalloc/dist/tcmalloc/cpu_cache.cc @@ -43,6 +43,8 @@ std::string parseLineFromFile(const char* fname) { if (f != nullptr) { if (fgets(fstr, 1023, f) != nullptr) fstr[strlen(fstr) < 1 ? 0 : strlen(fstr) - 1] = '\0'; + else + fstr[0] = '\0'; fclose(f); } @@ -69,7 +71,8 @@ unsigned long long getMemorySizeLimitInBytes() { unsigned long long groupMemBytes = 0; std::string groupLimit = parseLineFromFile(file); - if (!groupLimit.empty() ) { + // The "max" value in cgroups v2 means no limit. + if (!groupLimit.empty() && groupLimit != "max") { return std::min(systemMemBytes, (unsigned long long)atoll(groupLimit.c_str())); } }