comparison win/dw.c @ 1332:c0f29ce1a879

Fixed too broad of an if() in dw_window_destroy on OS/2 and Windows... This code error caused memory to be leaked when destroying windows under some circumstances. Specifically unpacked or orphaned windows. Also fixed crashes or memory corruption when destroying unpacked windows on Windows...This is due to the object window not having a Box allocated.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 10 Nov 2011 19:10:00 +0000
parents 4c12170f003f
children 63e05ef4a59a
comparison
equal deleted inserted replaced
1331:4c12170f003f 1332:c0f29ce1a879
3732 if(!DW_HWND_OBJECT) 3732 if(!DW_HWND_OBJECT)
3733 { 3733 {
3734 dw_messagebox("Dynamic Windows", DW_MB_OK|DW_MB_ERROR, "Could not initialize the object window. error code %d", GetLastError()); 3734 dw_messagebox("Dynamic Windows", DW_MB_OK|DW_MB_ERROR, "Could not initialize the object window. error code %d", GetLastError());
3735 exit(1); 3735 exit(1);
3736 } 3736 }
3737
3738 /* Create empty box data */
3739 SetWindowLongPtr(DW_HWND_OBJECT, GWLP_USERDATA, (LONG_PTR)calloc(sizeof(Box), 1));
3737 3740
3738 /* We need the version to check capability like up-down controls */ 3741 /* We need the version to check capability like up-down controls */
3739 dwVersion = GetVersion(); 3742 dwVersion = GetVersion();
3740 dwComctlVer = GetDllVersion(TEXT("comctl32.dll")); 3743 dwComctlVer = GetDllVersion(TEXT("comctl32.dll"));
3741 3744
4030 HMENU menu = GetMenu(handle); 4033 HMENU menu = GetMenu(handle);
4031 4034
4032 if(menu) 4035 if(menu)
4033 _free_menu_data(menu); 4036 _free_menu_data(menu);
4034 4037
4035 if(parent != HWND_DESKTOP && thisbox && thisbox->count) 4038 /* If it is a desktop window let WM_DESTROY handle it */
4036 { 4039 if(parent != HWND_DESKTOP)
4037 int z, index = -1; 4040 {
4038 Item *tmpitem, *thisitem = thisbox->items; 4041 /* If the parent box has items...
4039 4042 * try to remove it from the layout
4040 for(z=0;z<thisbox->count;z++) 4043 */
4041 { 4044 if(thisbox && thisbox->count)
4042 if(thisitem[z].hwnd == handle) 4045 {
4043 index = z; 4046 int z, index = -1;
4044 } 4047 Item *tmpitem, *thisitem = thisbox->items;
4045 4048
4046 if(index == -1) 4049 for(z=0;z<thisbox->count;z++)
4047 return 0; 4050 {
4048 4051 if(thisitem[z].hwnd == handle)
4049 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); 4052 index = z;
4050 4053 }
4051 /* Copy all but the current entry to the new list */ 4054
4052 for(z=0;z<index;z++) 4055 if(index == -1)
4053 { 4056 return 0;
4054 tmpitem[z] = thisitem[z]; 4057
4055 } 4058 tmpitem = malloc(sizeof(Item)*(thisbox->count-1));
4056 for(z=index+1;z<thisbox->count;z++) 4059
4057 { 4060 /* Copy all but the current entry to the new list */
4058 tmpitem[z-1] = thisitem[z]; 4061 for(z=0;z<index;z++)
4059 } 4062 {
4060 4063 tmpitem[z] = thisitem[z];
4061 thisbox->items = tmpitem; 4064 }
4062 free(thisitem); 4065 for(z=index+1;z<thisbox->count;z++)
4063 thisbox->count--; 4066 {
4067 tmpitem[z-1] = thisitem[z];
4068 }
4069
4070 thisbox->items = tmpitem;
4071 free(thisitem);
4072 thisbox->count--;
4073 }
4064 _free_window_memory(handle, 0); 4074 _free_window_memory(handle, 0);
4065 EnumChildWindows(handle, _free_window_memory, 0); 4075 EnumChildWindows(handle, _free_window_memory, 0);
4066 } 4076 }
4067 return DestroyWindow(handle); 4077 return DestroyWindow(handle);
4068 } 4078 }