Fix for deleting item from ListView bug

James Hatheway james at macadamian.com
Thu Feb 15 09:04:25 CST 2001


Hi,


There is a bug in LISTVIEW_DeleteItem that is causing my
application to crash.  Here is what is happening:
My application is calling ListView_DeleteItem macro,
which is ultimately handled by LISTVIEW_DeleteItem().
In this function, LVN_DELETEITEM notification is sent
back to the application.  During the message
handler for the notification inside the application,
it is calling LISTVIEW_GetItem with a LVIF_PARAM, which
returns (in the structure) a pointer to an internal
application structure, which the app then frees.
The problem is, that at this point some of the
listview data is *already* cleaned up, reflecting the
listview state as it will be AFTER the delete takes place,
so the wrong lparam is passed back in the LISTVIEW_GetItem
call.

For example: imagine that we have 3 items, we delete
item 1, during the LVN_DELETEITEM message handler when
we call LISTVIEW_GetItem we get back the lparam for item
2 (the next one in the list) not 1! This lparam is deleted,
so when we later on try to get the item data for the new
item 1, it is already deleted, so there is a crash when
we try to use it.

This patch moves the LVN_DELETEITEM notification to be
the first thing done, and it seems to work fine.


Changelog:
  James Hatheway - james at macadamian.com
  Send LVN_DELETEITEM notification first, to avoid crashes
  if the app requests LVIF_PARAM with LISTVIEW_GetItem()
  during its LVN_DELETEITEM message handler.

Modified:
  dlls/comctl32/listview.c




--
James Hatheway
Software Designer - Macadamian Technologies, Inc.
james at macadamian.com ~ http://www.macadamian.com

  "Man könnte froh sein, wenn die Luft so rein wäre wie das Bier"
  "One could be happy if the air were as pure as the beer"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ListView_DeleteItemFix.diff
Type: application/octet-stream
Size: 1379 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20010215/5b981297/ListView_DeleteItemFix.obj


More information about the wine-patches mailing list