@@ -180,6 +180,10 @@ handle_io_progress(Request *req)
180180 CloseHandle (req -> handles .hFile );
181181 }
182182
183+ if (req -> source == REQ_SRC_CACHE ) {
184+ UnlockUrlCacheEntryFileA (req -> originalUrl , 0 );
185+ }
186+
183187 if (req -> source == REQ_SRC_HTTP ) {
184188 if (req -> handles .http .hReq != NULL ) {
185189 InternetCloseHandle (req -> handles .http .hReq );
@@ -248,7 +252,8 @@ try_init_from_cache(Request *req)
248252 }
249253
250254 /* If we have internet, check the last modified time of the resource. If it's newer than what we have cached, bail. */
251- hUrl = InternetOpenUrlA (hInternet , req -> url , NULL , 0 , 0 , (DWORD_PTR )NULL );
255+ hUrl = InternetOpenUrlA (hInternet , req -> url , NULL , 0 ,
256+ INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE , (DWORD_PTR )NULL );
252257 lenlen = sizeof (modifiedTimeSys );
253258 if (hUrl != NULL
254259 && HttpQueryInfoA (hUrl , HTTP_QUERY_FLAG_SYSTEMTIME | HTTP_QUERY_LAST_MODIFIED , & modifiedTimeSys , & lenlen , 0 )
@@ -268,6 +273,9 @@ try_init_from_cache(Request *req)
268273 success = true;
269274
270275cleanup :
276+ if (!success ) {
277+ UnlockUrlCacheEntryFileA (req -> url , 0 );
278+ }
271279 if (hUrl != NULL ) {
272280 InternetCloseHandle (hUrl );
273281 }
@@ -494,16 +502,24 @@ VOID CALLBACK
494502handle_request (PTP_CALLBACK_INSTANCE inst , void * reqArg , PTP_WORK work )
495503{
496504 Request * req ;
505+ bool done ;
497506
498507 req = (Request * )reqArg ;
499- while (!req -> done ) {
508+ done = false;
509+ while (!done ) {
500510 if (req -> source == REQ_SRC_UNSET ) {
501511 init_request (req );
502512 }
503513 if (!req -> failed ) {
504514 progress_request (req );
505515 }
506516
517+ /*
518+ * Capture done state before posting to the main thread,
519+ * since the main thread may free req after processing.
520+ */
521+ done = req -> done || req -> failed ;
522+
507523 if (req -> hOutFile != INVALID_HANDLE_VALUE ) {
508524 /* write directly to output file */
509525 DWORD written ;
0 commit comments