comparison os2/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 e32b5e5595cd
comparison
equal deleted inserted replaced
1331:4c12170f003f 1332:c0f29ce1a879
4066 frame = (HWND)dw_window_get_data(handle, "_dw_combo_box"); 4066 frame = (HWND)dw_window_get_data(handle, "_dw_combo_box");
4067 4067
4068 if((menu = WinWindowFromID(handle, FID_MENU)) != NULLHANDLE) 4068 if((menu = WinWindowFromID(handle, FID_MENU)) != NULLHANDLE)
4069 _free_menu_data(menu); 4069 _free_menu_data(menu);
4070 4070
4071 if(parent != desktop && thisbox && thisbox->count) 4071 /* If it is a desktop window let WM_DESTROY handle it */
4072 { 4072 if(parent != desktop)
4073 int z, index = -1; 4073 {
4074 Item *tmpitem, *thisitem = thisbox->items; 4074 /* If the parent box has items...
4075 4075 * try to remove it from the layout
4076 for(z=0;z<thisbox->count;z++) 4076 */
4077 { 4077 if(thisbox && thisbox->count)
4078 if(thisitem[z].hwnd == handle) 4078 {
4079 index = z; 4079 int z, index = -1;
4080 } 4080 Item *tmpitem, *thisitem = thisbox->items;
4081 4081
4082 if(index == -1) 4082 for(z=0;z<thisbox->count;z++)
4083 return 0; 4083 {
4084 4084 if(thisitem[z].hwnd == handle)
4085 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); 4085 index = z;
4086 4086 }
4087 /* Copy all but the current entry to the new list */ 4087
4088 for(z=0;z<index;z++) 4088 if(index == -1)
4089 { 4089 return 0;
4090 tmpitem[z] = thisitem[z]; 4090
4091 } 4091 tmpitem = malloc(sizeof(Item)*(thisbox->count-1));
4092 for(z=index+1;z<thisbox->count;z++) 4092
4093 { 4093 /* Copy all but the current entry to the new list */
4094 tmpitem[z-1] = thisitem[z]; 4094 for(z=0;z<index;z++)
4095 } 4095 {
4096 4096 tmpitem[z] = thisitem[z];
4097 thisbox->items = tmpitem; 4097 }
4098 free(thisitem); 4098 for(z=index+1;z<thisbox->count;z++)
4099 thisbox->count--; 4099 {
4100 tmpitem[z-1] = thisitem[z];
4101 }
4102
4103 thisbox->items = tmpitem;
4104 free(thisitem);
4105 thisbox->count--;
4106 }
4100 _free_window_memory(frame ? frame : handle); 4107 _free_window_memory(frame ? frame : handle);
4101 } 4108 }
4102 return WinDestroyWindow(frame ? frame : handle); 4109 return WinDestroyWindow(frame ? frame : handle);
4103 } 4110 }
4104 4111