@@ -1006,7 +1006,7 @@ static int open_sharedmem_file(const char* filename, int oflags, TRAPS) {
1006
1006
// check to see if the file is secure
1007
1007
if (!is_file_secure (fd, filename)) {
1008
1008
::close (fd);
1009
- return - 1 ;
1009
+ return OS_ERR ;
1010
1010
}
1011
1011
1012
1012
return fd;
@@ -1173,8 +1173,6 @@ static void mmap_attach_shared(int vmid, char** addr, size_t* sizep, TRAPS) {
1173
1173
int mmap_prot = PROT_READ;
1174
1174
int file_flags = O_RDONLY | O_NOFOLLOW;
1175
1175
1176
- ResourceMark rm;
1177
-
1178
1176
// for linux, determine if vmid is for a containerized process
1179
1177
int nspid = LINUX_ONLY (os::Linux::get_namespace_pid (vmid)) NOT_LINUX (-1 );
1180
1178
const char * luser = get_user_name (vmid, &nspid, CHECK);
@@ -1196,29 +1194,18 @@ static void mmap_attach_shared(int vmid, char** addr, size_t* sizep, TRAPS) {
1196
1194
" Process not found" );
1197
1195
}
1198
1196
1197
+ // open the shared memory file for the give vmid
1199
1198
char * filename = get_sharedmem_filename (dirname, vmid, nspid);
1200
1199
1201
- // copy heap memory to resource memory. the open_sharedmem_file
1202
- // method below need to use the filename, but could throw an
1203
- // exception. using a resource array prevents the leak that
1204
- // would otherwise occur.
1205
- char * rfilename = NEW_RESOURCE_ARRAY (char , strlen (filename) + 1 );
1206
- strcpy (rfilename, filename);
1200
+ // We don't use CHECK as we need to free the strings even if an exception occurred.
1201
+ int fd = open_sharedmem_file (filename, file_flags, THREAD);
1207
1202
1208
1203
// free the c heap resources that are no longer needed
1209
1204
FREE_C_HEAP_ARRAY (char , luser);
1210
1205
FREE_C_HEAP_ARRAY (char , dirname);
1211
1206
FREE_C_HEAP_ARRAY (char , filename);
1212
1207
1213
- // open the shared memory file for the give vmid
1214
- int fd = open_sharedmem_file (rfilename, file_flags, THREAD);
1215
-
1216
- if (fd == OS_ERR) {
1217
- return ;
1218
- }
1219
-
1220
- if (HAS_PENDING_EXCEPTION) {
1221
- ::close (fd);
1208
+ if (fd == OS_ERR || HAS_PENDING_EXCEPTION) {
1222
1209
return ;
1223
1210
}
1224
1211
0 commit comments