Skip to content

Commit 9952492

Browse files
committed
Add testhandlecount command to check Windows handle leaks
1 parent 76f4308 commit 9952492

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

generic/tclTest.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ static Tcl_ObjCmdProc TestInterpResolverCmd;
334334
static Tcl_ObjCmdProc TestcpuidCmd;
335335
#endif
336336
static Tcl_ObjCmdProc TestApplyLambdaCmd;
337+
#ifdef _WIN32
338+
static Tcl_ObjCmdProc TestHandleCountCmd;
339+
#endif
337340

338341
static const Tcl_Filesystem testReportingFilesystem = {
339342
"reporting",
@@ -725,6 +728,10 @@ Tcltest_Init(
725728
NULL, NULL);
726729
Tcl_CreateObjCommand(interp, "testlutil", TestLutilCmd,
727730
NULL, NULL);
731+
#if defined(_WIN32)
732+
Tcl_CreateObjCommand(interp, "testhandlecount", TestHandleCountCmd,
733+
NULL, NULL);
734+
#endif
728735

729736
if (TclObjTest_Init(interp) != TCL_OK) {
730737
return TCL_ERROR;
@@ -8792,6 +8799,46 @@ TestLutilCmd(
87928799
return ret;
87938800
}
87948801

8802+
#ifdef _WIN32
8803+
/*
8804+
*----------------------------------------------------------------------
8805+
*
8806+
* TestHandleCountCmd --
8807+
*
8808+
* This procedure implements the "testhandlecount" command. It returns
8809+
* the number of open handles in the process.
8810+
*
8811+
* Results:
8812+
* A standard Tcl result.
8813+
*
8814+
* Side effects:
8815+
* None.
8816+
*
8817+
*----------------------------------------------------------------------
8818+
*/
8819+
8820+
static int
8821+
TestHandleCountCmd(
8822+
TCL_UNUSED(void *),
8823+
Tcl_Interp *interp, /* Current interpreter. */
8824+
int objc, /* Number of arguments. */
8825+
Tcl_Obj *const objv[]) /* Arguments. */
8826+
{
8827+
DWORD count;
8828+
if (objc != 1) {
8829+
Tcl_WrongNumArgs(interp, 1, objv, "");
8830+
return TCL_ERROR;
8831+
}
8832+
if (GetProcessHandleCount(GetCurrentProcess(), &count)) {
8833+
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(count));
8834+
return TCL_OK;
8835+
}
8836+
Tcl_SetObjResult(interp, Tcl_NewStringObj(
8837+
"GetProcessHandleCount failed", -1));
8838+
return TCL_ERROR;
8839+
}
8840+
#endif /* _WIN32 */
8841+
87958842
/*
87968843
* Local Variables:
87978844
* mode: c

0 commit comments

Comments
 (0)