8286431: Do not use resource array in posix mmap_attach_shared()
Reviewed-by: dholmes, jsjolen
This commit is contained in:
parent
4d9a1cd26f
commit
521e71222a
@ -1006,7 +1006,7 @@ static int open_sharedmem_file(const char* filename, int oflags, TRAPS) {
|
|||||||
// check to see if the file is secure
|
// check to see if the file is secure
|
||||||
if (!is_file_secure(fd, filename)) {
|
if (!is_file_secure(fd, filename)) {
|
||||||
::close(fd);
|
::close(fd);
|
||||||
return -1;
|
return OS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
@ -1173,8 +1173,6 @@ static void mmap_attach_shared(int vmid, char** addr, size_t* sizep, TRAPS) {
|
|||||||
int mmap_prot = PROT_READ;
|
int mmap_prot = PROT_READ;
|
||||||
int file_flags = O_RDONLY | O_NOFOLLOW;
|
int file_flags = O_RDONLY | O_NOFOLLOW;
|
||||||
|
|
||||||
ResourceMark rm;
|
|
||||||
|
|
||||||
// for linux, determine if vmid is for a containerized process
|
// for linux, determine if vmid is for a containerized process
|
||||||
int nspid = LINUX_ONLY(os::Linux::get_namespace_pid(vmid)) NOT_LINUX(-1);
|
int nspid = LINUX_ONLY(os::Linux::get_namespace_pid(vmid)) NOT_LINUX(-1);
|
||||||
const char* luser = get_user_name(vmid, &nspid, CHECK);
|
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) {
|
|||||||
"Process not found");
|
"Process not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// open the shared memory file for the give vmid
|
||||||
char* filename = get_sharedmem_filename(dirname, vmid, nspid);
|
char* filename = get_sharedmem_filename(dirname, vmid, nspid);
|
||||||
|
|
||||||
// copy heap memory to resource memory. the open_sharedmem_file
|
// We don't use CHECK as we need to free the strings even if an exception occurred.
|
||||||
// method below need to use the filename, but could throw an
|
int fd = open_sharedmem_file(filename, file_flags, THREAD);
|
||||||
// exception. using a resource array prevents the leak that
|
|
||||||
// would otherwise occur.
|
|
||||||
char* rfilename = NEW_RESOURCE_ARRAY(char, strlen(filename) + 1);
|
|
||||||
strcpy(rfilename, filename);
|
|
||||||
|
|
||||||
// free the c heap resources that are no longer needed
|
// free the c heap resources that are no longer needed
|
||||||
FREE_C_HEAP_ARRAY(char, luser);
|
FREE_C_HEAP_ARRAY(char, luser);
|
||||||
FREE_C_HEAP_ARRAY(char, dirname);
|
FREE_C_HEAP_ARRAY(char, dirname);
|
||||||
FREE_C_HEAP_ARRAY(char, filename);
|
FREE_C_HEAP_ARRAY(char, filename);
|
||||||
|
|
||||||
// open the shared memory file for the give vmid
|
if (fd == OS_ERR || HAS_PENDING_EXCEPTION) {
|
||||||
int fd = open_sharedmem_file(rfilename, file_flags, THREAD);
|
|
||||||
|
|
||||||
if (fd == OS_ERR) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAS_PENDING_EXCEPTION) {
|
|
||||||
::close(fd);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user