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

os::realloc should return a valid pointer for input size=0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 10
    • 9
    • hotspot
    • None
    • b21

    Description

      Currently, if os::realloc() is called with size=0, it will return NULL.

      os::realloc() mimicks the C-Runtime realloc function and, like malloc, has two options of dealing with input size 0: 1) It can either return NULL or 2) return a unique non-NULL pointer which can be passed to free (os::free in this case).

      os::realloc() should do (2) because:
      - there are callers which do interpret a return value of NULL as an OOM scenario without checking (e.g. ReallocateHeap(), which is used for the REALLOC_C_HEAP_ARRAY macro)
      - it would be consistent with the behaviour of os::malloc() in case of size=0

      Note that right now the behaviour may be also inconsistent in release builds, because there we call the native ::realloc function and live with whatever way it deals with size=0. So the behaviour may differ between assert- and non-assert builds and also between platforms.

      Please note that this only affects the hotspot. os::realloc is exposed to the JDK via Unsafe.reallocateMemory(), but that method explicitly handles an input size of 0 instead of relying on the return value of os::realloc().


      Attachments

        Activity

          People

            stuefe Thomas Stuefe
            stuefe Thomas Stuefe
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: