Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file handle leak in isRunningInContainer() function #3497

Merged
merged 1 commit into from
Jan 23, 2019
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
6 changes: 5 additions & 1 deletion port/unix/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4259,6 +4259,7 @@ static int32_t
isRunningInContainer(struct OMRPortLibrary *portLibrary, BOOLEAN *inContainer)
{
int32_t rc = 0;
FILE *cgroupFile = NULL;

/* Assume we are not in container */
*inContainer = FALSE;
Expand All @@ -4269,7 +4270,7 @@ isRunningInContainer(struct OMRPortLibrary *portLibrary, BOOLEAN *inContainer)
* then the process is not running in a container.
* For any other cgroup name, assume we are in a container.
*/
FILE *cgroupFile = fopen(OMR_PROC_PID_ONE_CGROUP_FILE, "r");
cgroupFile = fopen(OMR_PROC_PID_ONE_CGROUP_FILE, "r");

if (NULL == cgroupFile) {
int32_t osErrCode = errno;
Expand Down Expand Up @@ -4322,6 +4323,9 @@ isRunningInContainer(struct OMRPortLibrary *portLibrary, BOOLEAN *inContainer)
}
Trc_PRT_isRunningInContainer_container_detected((uintptr_t)*inContainer);
_end:
if (NULL != cgroupFile) {
fclose(cgroupFile);
}
return rc;
}

Expand Down