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

imageFile should use delete[] with new[]

    XMLWordPrintable

    Details

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

      Description

      There are several places in imageFile.cpp where "delete" operator is used instead of "delete []" for objects allocated with "new []":

      http://hg.openjdk.java.net/jdk9/dev/jdk/file/03453e4301fc/src/java.base/share/native/libjimage/imageFile.cpp

      ...
      _data = new u1[(size_t)data_size];
      ...
      // Release module data resource.
      ImageModuleData::~ImageModuleData() {
          if (_data) {
              delete _data;
          }
      }
      ...

      ...
      ImageFileReaderTable::ImageFileReaderTable() : _count(0), _max(_growth) {
          _table = new ImageFileReader*[_max];
      }

      ImageFileReaderTable::~ImageFileReaderTable() {
          delete _table;
      }
      ...

      ...
      _name = new char[len];
      ...
      ImageFileReader::~ImageFileReader() {
          // Ensure file is closed.
          close();
          // Free up name.
          if (_name) {
              delete _name;
              _name = NULL;
          }
      }
      ...

      ...
      compressed_data = new u1[(u4)compressed_size];
      ...
      delete compressed_data;
      ...

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

      http://cr.openjdk.java.net/~asmotrak/image_file_new_delete/webrev.00/

        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: