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