Merged memory leak fix from SDL 1.2 SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Sat, 24 Jun 2006 03:43:21 +0000
branchSDL-1.3
changeset 170403fb364e3283
parent 1703 a51dfda0ff33
child 1705 fc731a7d83ed
Merged memory leak fix from SDL 1.2
src/video/windib/SDL_dibvideo.c
     1.1 --- a/src/video/windib/SDL_dibvideo.c	Sat Jun 24 02:48:55 2006 +0000
     1.2 +++ b/src/video/windib/SDL_dibvideo.c	Sat Jun 24 03:43:21 2006 +0000
     1.3 @@ -426,6 +426,7 @@
     1.4      ReleaseDC(SDL_Window, hdc);
     1.5      return (depth);
     1.6  #else
     1.7 +    int depth;
     1.8      int dib_size;
     1.9      LPBITMAPINFOHEADER dib_hdr;
    1.10      HDC hdc;
    1.11 @@ -454,25 +455,32 @@
    1.12      DeleteObject(hbm);
    1.13      ReleaseDC(NULL, hdc);
    1.14  
    1.15 +    depth = 0;
    1.16      switch (dib_hdr->biBitCount) {
    1.17      case 8:
    1.18 -        return 8;
    1.19 +        depth = 8;
    1.20 +        break;
    1.21      case 24:
    1.22 -        return 24;
    1.23 +        depth = 24;
    1.24 +        break;
    1.25      case 32:
    1.26 -        return 32;
    1.27 +        depth = 32;
    1.28 +        break;
    1.29      case 16:
    1.30          if (dib_hdr->biCompression == BI_BITFIELDS) {
    1.31              /* check the red mask */
    1.32              switch (((DWORD *) ((char *) dib_hdr + dib_hdr->biSize))[0]) {
    1.33              case 0xf800:
    1.34 -                return 16;      /* 565 */
    1.35 +                depth = 16;
    1.36 +                break;          /* 565 */
    1.37              case 0x7c00:
    1.38 -                return 15;      /* 555 */
    1.39 +                depth = 15;
    1.40 +                break;          /* 555 */
    1.41              }
    1.42          }
    1.43      }
    1.44 -    return 0;                   /* poo. */
    1.45 +    SDL_free(dib_hdr);
    1.46 +    return depth;
    1.47  #endif /* NO_GETDIBITS */
    1.48  }
    1.49  
    1.50 @@ -595,8 +603,8 @@
    1.51                  if (settings.dmDisplayOrientation != rotation) {
    1.52                      // go to landscape
    1.53                      this->hidden->origRotation = rotation;
    1.54 -                    ChangeDisplaySettingsEx(NULL, &settings, NULL,
    1.55 -                                            CDS_RESET, NULL);
    1.56 +                    ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_RESET,
    1.57 +                                            NULL);
    1.58                  }
    1.59              }
    1.60              if ((width < GetDeviceCaps(GetDC(NULL), HORZRES))
    1.61 @@ -612,8 +620,8 @@
    1.62                  if (settings.dmDisplayOrientation != rotation) {
    1.63                      // go to portrait
    1.64                      this->hidden->origRotation = rotation;
    1.65 -                    ChangeDisplaySettingsEx(NULL, &settings, NULL,
    1.66 -                                            CDS_RESET, NULL);
    1.67 +                    ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_RESET,
    1.68 +                                            NULL);
    1.69                  }
    1.70              }
    1.71  
    1.72 @@ -1050,6 +1058,8 @@
    1.73  void
    1.74  DIB_VideoQuit(_THIS)
    1.75  {
    1.76 +    int i, j;
    1.77 +
    1.78      /* Destroy the window and everything associated with it */
    1.79      if (SDL_Window) {
    1.80          /* Delete the screen bitmap (also frees screen->pixels) */
    1.81 @@ -1060,7 +1070,7 @@
    1.82                  ShowWindow(SDL_Window, SW_HIDE);
    1.83              }
    1.84  #endif
    1.85 -            if (this->screen->flags & SDL_INTERNALOPENGL) {
    1.86 +            if (this->screen->flags & SDL_OPENGL) {
    1.87                  WIN_GL_ShutDown(this);
    1.88              }
    1.89              this->screen->pixels = NULL;
    1.90 @@ -1086,7 +1096,18 @@
    1.91              aygshell = NULL;
    1.92          }
    1.93  #endif
    1.94 +    }
    1.95  
    1.96 +    for (i = 0; i < SDL_arraysize(SDL_modelist); ++i) {
    1.97 +        if (!SDL_modelist[i]) {
    1.98 +            continue;
    1.99 +        }
   1.100 +        for (j = 0; SDL_modelist[i][j]; ++j) {
   1.101 +            SDL_free(SDL_modelist[i][j]);
   1.102 +        }
   1.103 +        SDL_free(SDL_modelist[i]);
   1.104 +        SDL_modelist[i] = NULL;
   1.105 +        SDL_nummodes[i] = 0;
   1.106      }
   1.107  }
   1.108