Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/common/processing_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
if (exePath)
{
snprintf(filePath, sizeof(filePath), "/proc/%d/exe", (int)pid);
ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX);
ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1);
char buf[PATH_MAX];
ssize_t length = readlink(filePath, buf, PATH_MAX - 1);
if (length > 0) // doesn't contain trailing NUL
{
exePath->chars[length] = '\0';
exePath->length = (uint32_t) length;
buf[length] = '\0';
ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length + 1); // +1 for the NUL
ffStrbufAppendNS(exePath, (uint32_t)length, buf);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does save some heap memory. Make sense.

}
}

Expand Down Expand Up @@ -242,7 +243,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons

#elif defined(__sun)

char filePath[PATH_MAX];
char filePath[128];
snprintf(filePath, sizeof(filePath), "/proc/%d/psinfo", (int) pid);
psinfo_t proc;
if (ffReadFileData(filePath, sizeof(proc), &proc) == sizeof(proc))
Expand All @@ -254,12 +255,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
if (exePath)
{
snprintf(filePath, sizeof(filePath), "/proc/%d/path/a.out", (int) pid);
ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX);
ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1);
char buf[PATH_MAX];
ssize_t length = readlink(filePath, buf, PATH_MAX - 1);
if (length > 0) // doesn't contain trailing NUL
{
exePath->chars[length] = '\0';
exePath->length = (uint32_t) length;
buf[length] = '\0';
ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length + 1); // +1 for the NUL
ffStrbufAppendNS(exePath, (uint32_t)length, buf);
}
}

Expand Down
Loading