mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
Fix parsing of linux memory
If process name contains a space, this parsing fails for no good reason.
This commit is contained in:
@@ -47,11 +47,26 @@ int OS::GetMemory(size_t *rss, size_t *vsize) {
|
||||
int itmp;
|
||||
char ctmp;
|
||||
size_t page_size = getpagesize();
|
||||
char *cbuf;
|
||||
bool foundExeEnd;
|
||||
|
||||
/* PID */
|
||||
if (fscanf(f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
|
||||
/* Exec file */
|
||||
if (fscanf (f, "%s ", buf) == 0) goto error; /* coverity[secure_coding] */
|
||||
cbuf = buf;
|
||||
foundExeEnd = false;
|
||||
if (fscanf (f, "%c", cbuf++) == 0) goto error; // (
|
||||
while (1) {
|
||||
if (fscanf(f, "%c", cbuf) == 0) goto error;
|
||||
if (*cbuf == ')') {
|
||||
foundExeEnd = true;
|
||||
} else if (foundExeEnd && *cbuf == ' ') {
|
||||
*cbuf = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
cbuf++;
|
||||
}
|
||||
/* State */
|
||||
if (fscanf (f, "%c ", &ctmp) == 0) goto error; /* coverity[secure_coding] */
|
||||
/* Parent process */
|
||||
|
||||
Reference in New Issue
Block a user