free unicodeOldName on error paths

WS_MoveFileA allocated unicodeOldName but did not free it when the
follow-up mbstowcs_s calls failed. Check the conversion result after
filling unicodeOldName, and free it before returning when the sizing
call for unicodeNewName fails.

Affected function: WS_MoveFileA.
Issue: F-50
pull/968/head
John Safranek 2026-05-07 10:49:27 -07:00 committed by Paul Adelsbach
parent 90d5d44910
commit 9ea6c7930d
1 changed files with 7 additions and 1 deletions

View File

@ -456,13 +456,19 @@ int WS_MoveFileA(const char* oldName, const char* newName, void* heap)
error = mbstowcs_s(&returnSz, unicodeOldName, unicodeOldNameSz,
oldName, oldNameSz);
if (error != 0) {
WFREE(unicodeOldName, heap, PORT_DYNTYPE_STRING);
return 0;
}
newNameSz = WSTRLEN(newName);
newName = TrimFileName(newName, &newNameSz);
error = mbstowcs_s(&unicodeNewNameSz, NULL, 0, newName, 0);
if (error != 0)
if (error != 0) {
WFREE(unicodeOldName, heap, PORT_DYNTYPE_STRING);
return 0;
}
unicodeNewName = (wchar_t*)WMALLOC((unicodeNewNameSz+1)*sizeof(wchar_t),
heap, PORT_DYNTYPE_STRING);