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 1704 03fb364e3283
parent 1703 a51dfda0ff33
child 1705 fc731a7d83ed
Merged memory leak fix from SDL 1.2
src/video/windib/SDL_dibvideo.c
--- a/src/video/windib/SDL_dibvideo.c	Sat Jun 24 02:48:55 2006 +0000
+++ b/src/video/windib/SDL_dibvideo.c	Sat Jun 24 03:43:21 2006 +0000
@@ -426,6 +426,7 @@
     ReleaseDC(SDL_Window, hdc);
     return (depth);
 #else
+    int depth;
     int dib_size;
     LPBITMAPINFOHEADER dib_hdr;
     HDC hdc;
@@ -454,25 +455,32 @@
     DeleteObject(hbm);
     ReleaseDC(NULL, hdc);
 
+    depth = 0;
     switch (dib_hdr->biBitCount) {
     case 8:
-        return 8;
+        depth = 8;
+        break;
     case 24:
-        return 24;
+        depth = 24;
+        break;
     case 32:
-        return 32;
+        depth = 32;
+        break;
     case 16:
         if (dib_hdr->biCompression == BI_BITFIELDS) {
             /* check the red mask */
             switch (((DWORD *) ((char *) dib_hdr + dib_hdr->biSize))[0]) {
             case 0xf800:
-                return 16;      /* 565 */
+                depth = 16;
+                break;          /* 565 */
             case 0x7c00:
-                return 15;      /* 555 */
+                depth = 15;
+                break;          /* 555 */
             }
         }
     }
-    return 0;                   /* poo. */
+    SDL_free(dib_hdr);
+    return depth;
 #endif /* NO_GETDIBITS */
 }
 
@@ -595,8 +603,8 @@
                 if (settings.dmDisplayOrientation != rotation) {
                     // go to landscape
                     this->hidden->origRotation = rotation;
-                    ChangeDisplaySettingsEx(NULL, &settings, NULL,
-                                            CDS_RESET, NULL);
+                    ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_RESET,
+                                            NULL);
                 }
             }
             if ((width < GetDeviceCaps(GetDC(NULL), HORZRES))
@@ -612,8 +620,8 @@
                 if (settings.dmDisplayOrientation != rotation) {
                     // go to portrait
                     this->hidden->origRotation = rotation;
-                    ChangeDisplaySettingsEx(NULL, &settings, NULL,
-                                            CDS_RESET, NULL);
+                    ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_RESET,
+                                            NULL);
                 }
             }
 
@@ -1050,6 +1058,8 @@
 void
 DIB_VideoQuit(_THIS)
 {
+    int i, j;
+
     /* Destroy the window and everything associated with it */
     if (SDL_Window) {
         /* Delete the screen bitmap (also frees screen->pixels) */
@@ -1060,7 +1070,7 @@
                 ShowWindow(SDL_Window, SW_HIDE);
             }
 #endif
-            if (this->screen->flags & SDL_INTERNALOPENGL) {
+            if (this->screen->flags & SDL_OPENGL) {
                 WIN_GL_ShutDown(this);
             }
             this->screen->pixels = NULL;
@@ -1086,7 +1096,18 @@
             aygshell = NULL;
         }
 #endif
+    }
 
+    for (i = 0; i < SDL_arraysize(SDL_modelist); ++i) {
+        if (!SDL_modelist[i]) {
+            continue;
+        }
+        for (j = 0; SDL_modelist[i][j]; ++j) {
+            SDL_free(SDL_modelist[i][j]);
+        }
+        SDL_free(SDL_modelist[i]);
+        SDL_modelist[i] = NULL;
+        SDL_nummodes[i] = 0;
     }
 }