[comctl32] Reduce memory usage of the syslink control (Take 4)
Alexandre Julliard
julliard at winehq.org
Tue Jan 3 10:06:56 CST 2006
Thomas Weidenmueller <wine-patches at reactsoft.com> writes:
> @@ -1062,35 +1063,41 @@
>
> if(Item->mask & LIF_ITEMID)
> {
> - if(!di->u.Link.szID)
> + if(di->u.Link.szID)
> {
> - di->u.Link.szID = Alloc((MAX_LINKID_TEXT + 1) * sizeof(WCHAR));
> - if(!Item->szID)
> - {
> - ERR("Unable to allocate memory for link id\n");
> - Ret = FALSE;
> - }
> + Free(di->u.Link.szID);
> }
> +
> + nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
> + di->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
> if(di->u.Link.szID)
> {
> - lstrcpynW(di->u.Link.szID, Item->szID, MAX_LINKID_TEXT + 1);
> + lstrcpynW(di->u.Link.szID, Item->szID, nc + 1);
> + }
> + else
> + {
> + ERR("Unable to allocate memory for link id\n");
> + Ret = FALSE;
> }
> }
You should probably make sure that the new text has been allocated
properly before freeing the old one, so that allocation errors don't
cause the current contents to be lost.
--
Alexandre Julliard
julliard at winehq.org
More information about the wine-devel
mailing list