@@ -2266,17 +2266,29 @@ static int GetDebugSignalHandlerMappingName(DWORD pid, wchar_t* buf,
2266
2266
static void DebugProcess (const FunctionCallbackInfo<Value>& args) {
2267
2267
Environment* env = Environment::GetCurrent (args);
2268
2268
Isolate* isolate = args.GetIsolate ();
2269
+
2270
+ if (args.Length () != 1 ) {
2271
+ env->ThrowError (" Invalid number of arguments." );
2272
+ return ;
2273
+ }
2274
+
2269
2275
HANDLE process = nullptr ;
2270
2276
HANDLE thread = nullptr ;
2271
2277
HANDLE mapping = nullptr ;
2272
2278
wchar_t mapping_name[32 ];
2273
2279
LPTHREAD_START_ROUTINE* handler = nullptr ;
2274
2280
DWORD pid = 0 ;
2275
2281
2276
- if (args.Length () != 1 ) {
2277
- env->ThrowError (" Invalid number of arguments." );
2278
- goto out;
2279
- }
2282
+ OnScopeLeave cleanup ([&]() {
2283
+ if (process != nullptr )
2284
+ CloseHandle (process);
2285
+ if (thread != nullptr )
2286
+ CloseHandle (thread);
2287
+ if (handler != nullptr )
2288
+ UnmapViewOfFile (handler);
2289
+ if (mapping != nullptr )
2290
+ CloseHandle (mapping);
2291
+ });
2280
2292
2281
2293
CHECK (args[0 ]->IsNumber ());
2282
2294
pid = args[0 ].As <Integer>()->Value ();
@@ -2289,22 +2301,22 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
2289
2301
if (process == nullptr ) {
2290
2302
isolate->ThrowException (
2291
2303
WinapiErrnoException (isolate, GetLastError (), " OpenProcess" ));
2292
- goto out ;
2304
+ return ;
2293
2305
}
2294
2306
2295
2307
if (GetDebugSignalHandlerMappingName (pid,
2296
2308
mapping_name,
2297
2309
arraysize (mapping_name)) < 0 ) {
2298
2310
env->ThrowErrnoException (errno, " sprintf" );
2299
- goto out ;
2311
+ return ;
2300
2312
}
2301
2313
2302
2314
mapping = OpenFileMappingW (FILE_MAP_READ, FALSE , mapping_name);
2303
2315
if (mapping == nullptr ) {
2304
2316
isolate->ThrowException (WinapiErrnoException (isolate,
2305
2317
GetLastError (),
2306
2318
" OpenFileMappingW" ));
2307
- goto out ;
2319
+ return ;
2308
2320
}
2309
2321
2310
2322
handler = reinterpret_cast <LPTHREAD_START_ROUTINE*>(
@@ -2316,7 +2328,7 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
2316
2328
if (handler == nullptr || *handler == nullptr ) {
2317
2329
isolate->ThrowException (
2318
2330
WinapiErrnoException (isolate, GetLastError (), " MapViewOfFile" ));
2319
- goto out ;
2331
+ return ;
2320
2332
}
2321
2333
2322
2334
thread = CreateRemoteThread (process,
@@ -2330,26 +2342,16 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
2330
2342
isolate->ThrowException (WinapiErrnoException (isolate,
2331
2343
GetLastError (),
2332
2344
" CreateRemoteThread" ));
2333
- goto out ;
2345
+ return ;
2334
2346
}
2335
2347
2336
2348
// Wait for the thread to terminate
2337
2349
if (WaitForSingleObject (thread, INFINITE) != WAIT_OBJECT_0) {
2338
2350
isolate->ThrowException (WinapiErrnoException (isolate,
2339
2351
GetLastError (),
2340
2352
" WaitForSingleObject" ));
2341
- goto out;
2342
- }
2343
-
2344
- out:
2345
- if (process != nullptr )
2346
- CloseHandle (process);
2347
- if (thread != nullptr )
2348
- CloseHandle (thread);
2349
- if (handler != nullptr )
2350
- UnmapViewOfFile (handler);
2351
- if (mapping != nullptr )
2352
- CloseHandle (mapping);
2353
+ return ;
2354
+ }
2353
2355
}
2354
2356
#endif // _WIN32
2355
2357
0 commit comments