Skip to content

Commit dba2f74

Browse files
committed
[0.4.8] [SETUPAPI] Apply yet uncommitted fix for CORE-12616 PR-408
This commit was *not* committed to master yet. I'll leave the ticket unresolved until it'll be. This fixes a regression introduced in SVN r73442: Our setup created undesired temporary files and left them in the temp folder. Also we saw a slight one-time-increase in memory consumption. This patch was the work of Carlo Bramini He proposed the fix on 2016-12-30 already. There are ongoing discussions about an alternative approach to the initial problem that SVN r73442 tried to address. Serge Gautherie can and shall be evaluate that alternative later during 0.4.9dev. For now many thanks to Carlo Bramini for this fix.
1 parent 8dc1609 commit dba2f74

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

dll/win32/setupapi/queue.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style,
10671067
OFSTRUCT OfStruct;
10681068
WCHAR TempPath[MAX_PATH];
10691069
WCHAR TempFile[MAX_PATH];
1070+
LONG lRes;
10701071
#endif
10711072

10721073
TRACE("copy %s to %s style 0x%x\n",debugstr_w(source),debugstr_w(target),style);
@@ -1078,11 +1079,6 @@ static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style,
10781079
ERR("GetTempPathW error\n");
10791080
return FALSE;
10801081
}
1081-
if (!GetTempFileNameW(TempPath, L"", 0, TempFile))
1082-
{
1083-
ERR("GetTempFileNameW(%s) error\n", debugstr_w(TempPath));
1084-
return FALSE;
1085-
}
10861082

10871083
/* Try to open the source file */
10881084
hSource = LZOpenFileW((LPWSTR)source, &OfStruct, OF_READ);
@@ -1092,25 +1088,45 @@ static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style,
10921088
return FALSE;
10931089
}
10941090

1091+
if (!GetTempFileNameW(TempPath, L"", 0, TempFile))
1092+
{
1093+
ERR("GetTempFileNameW(%s) error\n", debugstr_w(TempPath));
1094+
1095+
/* Close the source handle */
1096+
LZClose(hSource);
1097+
1098+
return FALSE;
1099+
}
1100+
10951101
/* Extract the compressed file to a temp location */
10961102
hTemp = LZOpenFileW(TempFile, &OfStruct, OF_CREATE);
10971103
if (hTemp < 0)
10981104
{
1099-
DWORD dwLastError = GetLastError();
1100-
11011105
ERR("LZOpenFileW(2) error %d %s\n", (int)hTemp, debugstr_w(TempFile));
11021106

11031107
/* Close the source handle */
11041108
LZClose(hSource);
11051109

1106-
/* Restore error condition triggered by LZOpenFileW */
1107-
SetLastError(dwLastError);
1110+
/* Delete temp file if an error is signaled */
1111+
DeleteFileW(TempFile);
1112+
11081113
return FALSE;
11091114
}
11101115

1111-
LZCopy(hSource, hTemp);
1116+
lRes = LZCopy(hSource, hTemp);
1117+
11121118
LZClose(hSource);
11131119
LZClose(hTemp);
1120+
1121+
if (lRes < 0)
1122+
{
1123+
ERR("LZCopy error %d (%s, %s)\n", (int)lRes, debugstr_w(source), debugstr_w(TempFile));
1124+
1125+
/* Delete temp file if copy was not successful */
1126+
DeleteFileW(TempFile);
1127+
1128+
return FALSE;
1129+
}
11141130
#endif
11151131

11161132
/* before copy processing */

0 commit comments

Comments
 (0)