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

Garbage collection can cause bad pointers, moved calls to unhand in file zip.c

XMLWordPrintable

    • jar
    • generic
    • generic

      For the JDK 116 release on the OpenVMS platform running on DIGITAL's
      hardware, DIGITAL has changed, the following JDK 116 source file
      in the shared part of the JDK.

      diff -c -r JDK116/src/share/java/zip/zip.c sun_JDK116/src/share/java/zip/zip.c
      *** JDK116/src/share/java/zip/zip.c Thu May 21 02:04:21 1998
      --- sun_JDK116/src/share/java/zip/zip.c Thu Apr 16 16:47:44 1998
      ***************
      *** 104,112 ****
        void
        java_util_zip_Inflater_init(Hjava_util_zip_Inflater *Hthis, long nowrap)
        {
      ! /* JLR: move to use point; GC will break this form. */
      ! /* following Digital Unix lead MPH __VMS */
      ! /* Classjava_util_zip_Inflater *this = unhand(Hthis); */
            z_stream *strm = calloc(1, sizeof(z_stream));
        
            if (strm == 0) {
      --- 96,102 ----
        void
        java_util_zip_Inflater_init(Hjava_util_zip_Inflater *Hthis, long nowrap)
        {
      ! Classjava_util_zip_Inflater *this = unhand(Hthis);
            z_stream *strm = calloc(1, sizeof(z_stream));
        
            if (strm == 0) {
      ***************
      *** 115,121 ****
         char *msg;
         switch (inflateInit2(strm, nowrap ? -MAX_WBITS : MAX_WBITS)) {
         case Z_OK:
      ! unhand(Hthis)->strm = (long)strm; /* JLR */
         return;
         case Z_MEM_ERROR:
         free(strm);
      --- 105,111 ----
         char *msg;
         switch (inflateInit2(strm, nowrap ? -MAX_WBITS : MAX_WBITS)) {
         case Z_OK:
      ! this->strm = (long)strm;
         return;
         case Z_MEM_ERROR:
         free(strm);
      ***************
      *** 184,199 ****
            strm->avail_in = this->len;
            strm->avail_out = len;
            switch (inflate(strm, Z_PARTIAL_FLUSH)) {
      - /* JLR: inflate() may trigger GC; need to re-unhand this */
              case Z_STREAM_END:
      ! unhand(Hthis)->finished = TRUE;
              case Z_OK:
      - this = unhand(Hthis); /* JLR */
         this->off += this->len - strm->avail_in;
         this->len = strm->avail_in;
         return len - strm->avail_out;
              case Z_NEED_DICT:
      - this = unhand(Hthis); /* JLR */
         this->needsDictionary = TRUE;
         /* We actually will have consumed some input here! */
         this->off += this->len - strm->avail_in;
      --- 174,186 ----
            strm->avail_in = this->len;
            strm->avail_out = len;
            switch (inflate(strm, Z_PARTIAL_FLUSH)) {
              case Z_STREAM_END:
      ! this->finished = TRUE;
              case Z_OK:
         this->off += this->len - strm->avail_in;
         this->len = strm->avail_in;
         return len - strm->avail_out;
              case Z_NEED_DICT:
         this->needsDictionary = TRUE;
         /* We actually will have consumed some input here! */
         this->off += this->len - strm->avail_in;
      ***************
      *** 282,289 ****
         SignalError(0, JAVAPKG "InternalError", 0);
         } else {
         free(strm);
      ! /* JLR: free might trigger GC and invalidate "this" */
      ! unhand(Hthis)->strm = 0;
         }
            }
        }
      --- 269,275 ----
         SignalError(0, JAVAPKG "InternalError", 0);
         } else {
         free(strm);
      ! this->strm = 0;
         }
            }
        }
      ***************
      *** 291,302 ****
        void
        java_util_zip_Deflater_init(Hjava_util_zip_Deflater *Hthis, long nowrap)
        {
      ! /* JLR: calloc can trigger GC; delay setting "this" */
      ! Classjava_util_zip_Deflater *this;
            z_stream *strm = calloc(1, sizeof(z_stream));
            char *msg;
        
      - this = unhand(Hthis); /* JLR */
            if (strm == 0) {
         SignalError(0, JAVAPKG "OutOfMemory", 0);
            } else {
      --- 277,286 ----
        void
        java_util_zip_Deflater_init(Hjava_util_zip_Deflater *Hthis, long nowrap)
        {
      ! Classjava_util_zip_Deflater *this = unhand(Hthis);
            z_stream *strm = calloc(1, sizeof(z_stream));
            char *msg;
        
            if (strm == 0) {
         SignalError(0, JAVAPKG "OutOfMemory", 0);
            } else {
      ***************
      *** 304,310 ****
         nowrap ? -MAX_WBITS : MAX_WBITS,
         DEF_MEM_LEVEL, this->strategy)) {
         case Z_OK:
      ! unhand(Hthis)->strm = (long)strm; /* JLR */
         return;
         case Z_MEM_ERROR:
         free(strm);
      --- 288,294 ----
         nowrap ? -MAX_WBITS : MAX_WBITS,
         DEF_MEM_LEVEL, this->strategy)) {
         case Z_OK:
      ! this->strm = (long)strm;
         return;
         case Z_MEM_ERROR:
         free(strm);
      ***************
      *** 390,400 ****
         }
            } else {
         switch (deflate(strm, this->finish ? Z_FINISH : Z_NO_FLUSH)) {
      - /* JLR: deflate can trigger GC, invalidating "this" */
         case Z_STREAM_END:
      ! unhand(Hthis)->finished = TRUE;
         case Z_OK:
      - this = unhand(Hthis); /* JLR */
         this->off += this->len - strm->avail_in;
         this->len = strm->avail_in;
         return len - strm->avail_out;
      --- 374,382 ----
         }
            } else {
         switch (deflate(strm, this->finish ? Z_FINISH : Z_NO_FLUSH)) {
         case Z_STREAM_END:
      ! this->finished = TRUE;
         case Z_OK:
         this->off += this->len - strm->avail_in;
         this->len = strm->avail_in;
         return len - strm->avail_out;
      ***************
      *** 460,467 ****
         SignalError(0, JAVAPKG "InternalError", 0);
         return;
            }
      - /* JLR: deflateReset might have triggered GC, trashed "this" */
      - this = unhand(Hthis);
            this->off = this->len = 0;
            this->finish = this->finished = FALSE;
        }
      --- 442,447 ----
      ***************
      *** 477,484 ****
         SignalError(0, JAVAPKG "InternalError", 0);
         } else {
         free(strm);
      ! /* JLR: re-unhand, since free can trigger GC */
      ! unhand(Hthis)->strm = 0;
         }
            }
        }
      --- 457,463 ----
         SignalError(0, JAVAPKG "InternalError", 0);
         } else {
         free(strm);
      ! this->strm = 0;
         }
            }
        }


            zlisunw Zhenghua Li (Inactive)
            jbenoit Jonathan Benoit (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: