Skip to content

Commit 35c1135

Browse files
Ashutosh Mehrapshipton
authored andcommitted
Fix file handle leak in isRunningInContainer() function
Close `cgroupFile` file handle at end of isRunningInContainer(). Signed-off-by: Ashutosh Mehra <[email protected]>
1 parent c0caded commit 35c1135

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

port/unix/omrsysinfo.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4259,6 +4259,7 @@ static int32_t
42594259
isRunningInContainer(struct OMRPortLibrary *portLibrary, BOOLEAN *inContainer)
42604260
{
42614261
int32_t rc = 0;
4262+
FILE *cgroupFile = NULL;
42624263

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

42744275
if (NULL == cgroupFile) {
42754276
int32_t osErrCode = errno;
@@ -4322,6 +4323,9 @@ isRunningInContainer(struct OMRPortLibrary *portLibrary, BOOLEAN *inContainer)
43224323
}
43234324
Trc_PRT_isRunningInContainer_container_detected((uintptr_t)*inContainer);
43244325
_end:
4326+
if (NULL != cgroupFile) {
4327+
fclose(cgroupFile);
4328+
}
43254329
return rc;
43264330
}
43274331

0 commit comments

Comments
 (0)