Skip to content

Commit

Permalink
Merge pull request #17 from pshipton/close
Browse files Browse the repository at this point in the history
Fix file handle leak in isRunningInContainer() function
  • Loading branch information
DanHeidinga authored Jan 24, 2019
2 parents c0caded + 35c1135 commit d2f4534
Showing 1 changed file with 5 additions and 1 deletion.
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

0 comments on commit d2f4534

Please sign in to comment.