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

libjimage should use delete[] with new[]

    XMLWordPrintable

    Details

    • Resolved In Build:
      b105
    • CPU:
      generic
    • OS:
      generic

      Description

      ImageNativeSubstrate.cpp uses "delete" operator instead of "delete []" when it allocates an array with "new" operator:

      http://hg.openjdk.java.net/jdk9/dev/jdk/file/20d991bc9171/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp#l213

      ...
          char* path = new char[size + 1];
          if (path == NULL) {
              return NULL;
          }
          memcpy(path, rawBytes, size);
          path[size] = '\0';
          // Locate resource location data.
          ImageLocation location;
          bool found = reader->find_location(path, location);
          delete path;
      ...

      As far as I know, behavior is undefined in this case. It would be better to use delete[]:

      diff -r 20d991bc9171 src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp
      --- a/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Mon Dec 28 00:02:06 2015 +0000
      +++ b/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Mon Dec 28 19:02:19 2015 -0800
      @@ -210,7 +210,7 @@
           // Locate resource location data.
           ImageLocation location;
           bool found = reader->find_location(path, location);
      - delete path;
      + delete[] path;
           // Resource not found.
           if (!found) return NULL;
           // Expand stream into array.

      See also similar JDK-8140649.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              asmotrak Artem Smotrakov
              Reporter:
              asmotrak Artem Smotrakov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: