Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8132892

Memory must be freed after calling Arguments::set_sysclasspath function

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • hotspot
    • b79

        Arguments::set_sysclasspath function call set_value method of SystemProperty class which copy passed value. In several code paths memory is allocated for string and then this string is passed to Arguments::set_sysclasspath. Therefore allocated string should be freed after calling Arguments::set_sysclasspath function.

        Here a list of function where memory must be freed:
        1) hotspot/src/share/vm/runtime/arguments.cpp module:
        jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) {
        ...
          if (scp_assembly_required) {
            // Assemble the bootclasspath elements into the final path.
            Arguments::set_sysclasspath(scp_p->combined_path());
          }
        ...

        combined_path() allocate memory for path and then pass resulting string to the set_sysclasspath function.

        2) hotspot/src/share/vm/runtime/os.cpp module:

        bool os::set_boot_path(char fileSep, char pathSep) {
        ...
          char* jimage = format_boot_path("%/lib/modules/" BOOT_IMAGE_NAME, home, home_len, fileSep, pathSep);
          if (jimage == NULL) return false;
          bool has_jimage = (os::stat(jimage, &st) == 0);
          if (has_jimage) {
            Arguments::set_sysclasspath(jimage);
            return true;
          }
        ...
          char* modules_dir = format_boot_path("%/modules", home, home_len, fileSep, pathSep);
          if (os::stat(modules_dir, &st) == 0) {
            if ((st.st_mode & S_IFDIR) == S_IFDIR) {
              sysclasspath = expand_entries_to_path(modules_dir, fileSep, pathSep);
            }
          }

          // fallback to classes
          if (sysclasspath == NULL)
            sysclasspath = format_boot_path("%/classes", home, home_len, fileSep, pathSep);

          if (sysclasspath == NULL) return false;
          Arguments::set_sysclasspath(sysclasspath);

          return true;
        }

        format_boot_path and expand_entries_to_path functions allocate memory for path, thus 'jimage', 'modules_dir' and 'sysclasspath' should be freed.

              ddmitriev Dmitry Dmitriev
              ddmitriev Dmitry Dmitriev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: