提交 d4c2794b 编写于 作者: N nroskill 提交者: LINGuanRen

fix coredump when fopen failed

上级 69facd62
......@@ -26,13 +26,12 @@
int64_t get_virtual_memory_used()
{
constexpr int BUFFER_SIZE = 128;
char filename[BUFFER_SIZE];
int64_t page_cnt = 0;
snprintf(filename, BUFFER_SIZE, "/proc/%d/statm", getpid());
FILE* statm = fopen(filename, "r");
fscanf(statm, "%ld", &page_cnt);
fclose(statm);
FILE* statm = fopen("/proc/self/statm", "r");
if (OB_NOT_NULL(statm)) {
fscanf(statm, "%ld", &page_cnt);
fclose(statm);
}
return page_cnt * sysconf(_SC_PAGESIZE);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册