changeset 1703:043db6b221c2

Cleanups on the icon creation code on OS/2. Make sure any temporary resources are destroyed.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 03 May 2012 18:44:08 +0000
parents 1b10b4534bc4
children 873304f581be
files os2/dw.c
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/os2/dw.c	Thu May 03 17:45:57 2012 +0000
+++ b/os2/dw.c	Thu May 03 18:44:08 2012 +0000
@@ -8907,7 +8907,7 @@
 }
 
 /* Internal function to create an icon from an existing pixmap */
-HICN _create_icon(char *file, HPIXMAP src)
+HICN _create_icon(HPIXMAP src)
 {
     HPIXMAP pntr = dw_pixmap_new(hwndApp, WinQuerySysValue(HWND_DESKTOP, SV_CXICON), WinQuerySysValue(HWND_DESKTOP, SV_CYICON), src->depth);
     HPIXMAP mask = dw_pixmap_new(hwndApp, pntr->width, pntr->height*2, 1);
@@ -8954,6 +8954,7 @@
 {
    char *file = alloca(strlen(filename) + 6);
    HPIXMAP src = alloca(sizeof(struct _hpixmap));
+   HICN icon = 0;
 
    if(!file || !src)
       return 0;
@@ -8977,14 +8978,25 @@
            strcat(file, image_exts[z]);
            if(access(file, 04) == 0 &&
               _load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth))
-               return _create_icon(file, src);
+           {
+               icon = _create_icon(src);
+               break;
+           }
        }
-       return 0;
    }
    else if(_load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth))
-       return _create_icon(file, src);
+       icon = _create_icon(src);
+   /* Free temporary resources if in use */
+   if(icon)
+   {
+       GpiSetBitmap(src->hps, NULLHANDLE);
+       GpiDeleteBitmap(src->hbm);
+       GpiAssociate(src->hps, NULLHANDLE);
+       GpiDestroyPS(src->hps);
+       DevCloseDC(src->hdc);
+   }
    /* Otherwise fall back to the classic method */
-   return WinLoadFileIcon((PSZ)file, FALSE);
+   return icon ? icon : WinLoadFileIcon((PSZ)file, FALSE);
 }
 
 /*