< prev index next >

src/os/windows/vm/perfMemory_windows.cpp

Print this page
rev 10257 : 8150379: [windows] Fix Leaks in perfMemory_windows.cpp
Reviewed-by:


 611 //
 612 // This method attempts to remove all stale shared memory files in
 613 // the named user temporary directory. It scans the named directory
 614 // for files matching the pattern ^$[0-9]*$. For each file found, the
 615 // process id is extracted from the file name and a test is run to
 616 // determine if the process is alive. If the process is not alive,
 617 // any stale file resources are removed.
 618 //
 619 static void cleanup_sharedmem_resources(const char* dirname) {
 620 
 621   // open the user temp directory
 622   DIR* dirp = os::opendir(dirname);
 623 
 624   if (dirp == NULL) {
 625     // directory doesn't exist, so there is nothing to cleanup
 626     return;
 627   }
 628 
 629   if (!is_directory_secure(dirname)) {
 630     // the directory is not secure, don't attempt any cleanup

 631     return;
 632   }
 633 
 634   // for each entry in the directory that matches the expected file
 635   // name pattern, determine if the file resources are stale and if
 636   // so, remove the file resources. Note, instrumented HotSpot processes
 637   // for this user may start and/or terminate during this search and
 638   // remove or create new files in this directory. The behavior of this
 639   // loop under these conditions is dependent upon the implementation of
 640   // opendir/readdir.
 641   //
 642   struct dirent* entry;
 643   char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
 644   errno = 0;
 645   while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) {
 646 
 647     int pid = filename_to_pid(entry->d_name);
 648 
 649     if (pid == 0) {
 650 


1607   if (user == NULL || strlen(user) == 0) {
1608     luser = get_user_name(vmid);
1609   }
1610   else {
1611     luser = user;
1612   }
1613 
1614   if (luser == NULL) {
1615     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1616               "Could not map vmid to user name");
1617   }
1618 
1619   // get the names for the resources for the target vm
1620   char* dirname = get_user_tmp_dir(luser);
1621 
1622   // since we don't follow symbolic links when creating the backing
1623   // store file, we also don't following them when attaching
1624   //
1625   if (!is_directory_secure(dirname)) {
1626     FREE_C_HEAP_ARRAY(char, dirname);



1627     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1628               "Process not found");
1629   }
1630 
1631   char* filename = get_sharedmem_filename(dirname, vmid);
1632   char* objectname = get_sharedmem_objectname(luser, vmid);
1633 
1634   // copy heap memory to resource memory. the objectname and
1635   // filename are passed to methods that may throw exceptions.
1636   // using resource arrays for these names prevents the leaks
1637   // that would otherwise occur.
1638   //
1639   char* rfilename = NEW_RESOURCE_ARRAY(char, strlen(filename) + 1);
1640   char* robjectname = NEW_RESOURCE_ARRAY(char, strlen(objectname) + 1);
1641   strcpy(rfilename, filename);
1642   strcpy(robjectname, objectname);
1643 
1644   // free the c heap resources that are no longer needed
1645   if (luser != user) FREE_C_HEAP_ARRAY(char, luser);
1646   FREE_C_HEAP_ARRAY(char, dirname);




 611 //
 612 // This method attempts to remove all stale shared memory files in
 613 // the named user temporary directory. It scans the named directory
 614 // for files matching the pattern ^$[0-9]*$. For each file found, the
 615 // process id is extracted from the file name and a test is run to
 616 // determine if the process is alive. If the process is not alive,
 617 // any stale file resources are removed.
 618 //
 619 static void cleanup_sharedmem_resources(const char* dirname) {
 620 
 621   // open the user temp directory
 622   DIR* dirp = os::opendir(dirname);
 623 
 624   if (dirp == NULL) {
 625     // directory doesn't exist, so there is nothing to cleanup
 626     return;
 627   }
 628 
 629   if (!is_directory_secure(dirname)) {
 630     // the directory is not secure, don't attempt any cleanup
 631     os::closedir(dirp);
 632     return;
 633   }
 634 
 635   // for each entry in the directory that matches the expected file
 636   // name pattern, determine if the file resources are stale and if
 637   // so, remove the file resources. Note, instrumented HotSpot processes
 638   // for this user may start and/or terminate during this search and
 639   // remove or create new files in this directory. The behavior of this
 640   // loop under these conditions is dependent upon the implementation of
 641   // opendir/readdir.
 642   //
 643   struct dirent* entry;
 644   char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
 645   errno = 0;
 646   while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) {
 647 
 648     int pid = filename_to_pid(entry->d_name);
 649 
 650     if (pid == 0) {
 651 


1608   if (user == NULL || strlen(user) == 0) {
1609     luser = get_user_name(vmid);
1610   }
1611   else {
1612     luser = user;
1613   }
1614 
1615   if (luser == NULL) {
1616     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1617               "Could not map vmid to user name");
1618   }
1619 
1620   // get the names for the resources for the target vm
1621   char* dirname = get_user_tmp_dir(luser);
1622 
1623   // since we don't follow symbolic links when creating the backing
1624   // store file, we also don't following them when attaching
1625   //
1626   if (!is_directory_secure(dirname)) {
1627     FREE_C_HEAP_ARRAY(char, dirname);
1628     if (luser != user) {
1629       FREE_C_HEAP_ARRAY(char, luser);
1630     }
1631     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1632               "Process not found");
1633   }
1634 
1635   char* filename = get_sharedmem_filename(dirname, vmid);
1636   char* objectname = get_sharedmem_objectname(luser, vmid);
1637 
1638   // copy heap memory to resource memory. the objectname and
1639   // filename are passed to methods that may throw exceptions.
1640   // using resource arrays for these names prevents the leaks
1641   // that would otherwise occur.
1642   //
1643   char* rfilename = NEW_RESOURCE_ARRAY(char, strlen(filename) + 1);
1644   char* robjectname = NEW_RESOURCE_ARRAY(char, strlen(objectname) + 1);
1645   strcpy(rfilename, filename);
1646   strcpy(robjectname, objectname);
1647 
1648   // free the c heap resources that are no longer needed
1649   if (luser != user) FREE_C_HEAP_ARRAY(char, luser);
1650   FREE_C_HEAP_ARRAY(char, dirname);


< prev index next >