@@ -112,7 +112,7 @@ cancel_request(Request *req)
112112 req -> failed = true;
113113}
114114
115- bool
115+ void
116116handle_io_progress (Request * req )
117117{
118118 NPError err ;
@@ -169,36 +169,16 @@ handle_io_progress(Request *req)
169169 logmsg ("destroystream error %d\n" , err );
170170 }
171171 free (req -> stream );
172+ req -> stream = NULL ;
172173 }
173174
174175 if (req -> doNotify ) {
175176 logmsg ("> NPP_UrlNotify %s %d %p\n" , req -> originalUrl , req -> doneReason , req -> notifyData );
176177 pluginFuncs .urlnotify (& npp , req -> originalUrl , req -> doneReason , req -> notifyData );
177178 }
178179
179- if ((req -> source == REQ_SRC_FILE || req -> source == REQ_SRC_CACHE ) && req -> handles .hFile != INVALID_HANDLE_VALUE ) {
180- CloseHandle (req -> handles .hFile );
181- }
182-
183- if (req -> source == REQ_SRC_CACHE ) {
184- UnlockUrlCacheEntryFileA (req -> originalUrl , 0 );
185- }
186-
187- if (req -> source == REQ_SRC_HTTP ) {
188- if (req -> handles .http .hReq != NULL ) {
189- InternetCloseHandle (req -> handles .http .hReq );
190- }
191- if (req -> handles .http .hConn != NULL ) {
192- InternetCloseHandle (req -> handles .http .hConn );
193- }
194- }
195-
196180 complete_request ();
197-
198- return true;
199181 }
200-
201- return false;
202182}
203183
204184void
@@ -570,28 +550,16 @@ VOID CALLBACK
570550handle_request (PTP_CALLBACK_INSTANCE inst , void * reqArg , PTP_WORK work )
571551{
572552 Request * req ;
573- HANDLE doneEvent ;
574- HANDLE readyEvent ;
575- bool done ;
576553
577554 req = (Request * )reqArg ;
578- doneEvent = req -> doneEvent ;
579- readyEvent = req -> readyEvent ;
580- done = false;
581- while (!done ) {
555+ while (true) {
582556 if (req -> source == REQ_SRC_UNSET ) {
583557 init_request (req );
584558 }
585559 if (!req -> failed ) {
586560 progress_request (req );
587561 }
588562
589- /*
590- * Capture done state before posting to the main thread,
591- * since the main thread may free req after processing.
592- */
593- done = req -> done || req -> failed ;
594-
595563 if (req -> hOutFile != INVALID_HANDLE_VALUE ) {
596564 /* write directly to output file */
597565 DWORD written ;
@@ -600,18 +568,40 @@ handle_request(PTP_CALLBACK_INSTANCE inst, void *reqArg, PTP_WORK work)
600568 }
601569 req -> writePtr = req -> writeSize ;
602570 } else {
603- /* notify main thread to pipe progress to the plugin */
571+ /* main thread has to pipe progress to the plugin */
604572 PostMessageW (hwnd , ioMsg , (WPARAM )NULL , (LPARAM )req );
605- WaitForSingleObject (readyEvent , INFINITE );
573+ WaitForSingleObject (req -> readyEvent , INFINITE );
574+ }
575+
576+ if (req -> done || req -> failed ) {
577+ break ;
578+ }
579+ }
580+
581+ /* cleanup I/O handles */
582+ if ((req -> source == REQ_SRC_FILE || req -> source == REQ_SRC_CACHE )
583+ && req -> handles .hFile != INVALID_HANDLE_VALUE ) {
584+ CloseHandle (req -> handles .hFile );
585+ }
586+ if (req -> source == REQ_SRC_CACHE ) {
587+ UnlockUrlCacheEntryFileA (req -> originalUrl , 0 );
588+ }
589+ if (req -> source == REQ_SRC_HTTP ) {
590+ if (req -> handles .http .hReq != NULL ) {
591+ InternetCloseHandle (req -> handles .http .hReq );
592+ }
593+ if (req -> handles .http .hConn != NULL ) {
594+ InternetCloseHandle (req -> handles .http .hConn );
606595 }
607596 }
608597
609- /* Close handles here, because req has been freed at this point */
610- if (doneEvent != INVALID_HANDLE_VALUE ) {
611- SetEvent (doneEvent );
612- CloseHandle (doneEvent );
598+ /* cleanup signals */
599+ if (req -> doneEvent != INVALID_HANDLE_VALUE ) {
600+ SetEvent (req -> doneEvent );
601+ CloseHandle (req -> doneEvent );
613602 }
614- CloseHandle (readyEvent );
603+ CloseHandle (req -> readyEvent );
604+ free (req );
615605}
616606
617607static void
0 commit comments