Skip to content

Commit 4d0a26d

Browse files
authored
[SHLWAPI][SHLWAPI_APITEST] Optimize StrRetToStrW WSTR handling (reactos#7513)
This avoids Alloc/Free while also matching the Windows behavior.
1 parent e3c859e commit 4d0a26d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

dll/win32/shlwapi/string.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,8 +1635,14 @@ HRESULT WINAPI StrRetToStrW(LPSTRRET lpStrRet, const ITEMIDLIST *pidl, LPWSTR *p
16351635
switch (lpStrRet->uType)
16361636
{
16371637
case STRRET_WSTR:
1638+
#ifdef __REACTOS__
1639+
hRet = lpStrRet->u.pOleStr ? S_OK : E_FAIL;
1640+
*ppszName = lpStrRet->u.pOleStr;
1641+
lpStrRet->u.pOleStr = NULL; /* Windows does this, presumably in case someone calls SHFree */
1642+
#else
16381643
hRet = SHStrDupW(lpStrRet->u.pOleStr, ppszName);
16391644
CoTaskMemFree(lpStrRet->u.pOleStr);
1645+
#endif
16401646
break;
16411647

16421648
case STRRET_CSTR:

modules/rostests/apitests/shlwapi/StrDup.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,25 @@ static void TEST_StrDupW(void)
3939
LocalFree(ptrW);
4040
}
4141

42+
static void TEST_StrRet(void)
43+
{
44+
LPWSTR input, output;
45+
if (SUCCEEDED(SHStrDupW(L"Test", &input)))
46+
{
47+
STRRET strret;
48+
strret.uType = STRRET_WSTR;
49+
U(strret).pOleStr = input;
50+
output = NULL;
51+
ok_int(StrRetToStrW(&strret, NULL, &output), S_OK);
52+
ok_ptr(U(strret).pOleStr, NULL);
53+
ok_ptr(input, output);
54+
CoTaskMemFree(output);
55+
}
56+
}
57+
4258
START_TEST(StrDup)
4359
{
4460
TEST_StrDupA();
4561
TEST_StrDupW();
62+
TEST_StrRet();
4663
}

0 commit comments

Comments
 (0)