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

Potential memory leak in error handling code in X11SurfaceData.c

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b32
    • CPU:
      x86
    • OS:
      linux

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.7.0_01"
        Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
        Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Linux zhouyx-workstation 3.0.0-16-generic #28-Ubuntu SMP Fri Jan 27 17:50:54 UTC 2012 i686 i686 i386 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :

        In X11SurfaceData.c, when memory allocation failed, the error handling code does not free the memory already allocated.

        eg.
        In following piece of code, if "shminfo->shmid = shmget(IPC_PRIVATE, height * img->bytes_per_line, PC_CREAT|0777); " failed, both "img" and "shminfo" are not freed.
         
        ////////////////////////////////////////////////////////////
            shminfo = malloc(sizeof(XShmSegmentInfo));
            if (shminfo == NULL) {
                return NULL;
            }
            memset(shminfo, 0, sizeof(XShmSegmentInfo));

            img = XShmCreateImage(awt_display, xsdo->configData->awt_visInfo.visual,
                                  xsdo->depth, ZPixmap, NULL, shminfo,
                                  width, height);
            if (img == NULL) {
                free((void *)shminfo);
                return NULL;
            }
            shminfo->shmid =
                shmget(IPC_PRIVATE, height * img->bytes_per_line, IPC_CREAT|0777);
            if (shminfo->shmid < 0) {
                J2dRlsTraceLn1(J2D_TRACE_ERROR,
                               "X11SD_SetupSharedSegment shmget has failed: %s",
                               strerror(errno));
                return NULL;
            }
        ////////////////////////////////////////////






        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        It is not easy to reproduce, we observed the memory leak only on one machine because it exists in error handling code and app rarely goes there.

        However, this bug is obvious when looking at the code.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        All allocated memory should be freed in error handling code.
        ACTUAL -
        Some allocated memory are not freed.

        REPRODUCIBILITY :
        This bug can be reproduced occasionally.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  prr Philip Race
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: