The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,262 other subscribers

Delphi and DUnitX: ensure you catch the ENoTestsRegistered exception

Posted by jpluimers on 2021/04/27

If you setup an empty test project, then DUnitX will throw an ENoTestsRegistered.

This exception is not handled, which results in two things:

  • a run-time error 217 if your application is a non-UI application
  • a memory leak detected by FastMM4

So better catch the ENoTestsRegistered exception in your .dpr level: a caught exception will be destroyed by the exception handling mechanism.

–jeroen

Leak example (the stack trace towards the top of the stack is in accurate; this is a Delphi problem with handling exceptions that bubble up to the main project entry point)

--------------------------------2019/5/7 13:10:33--------------------------------
A memory block has been leaked. The size is: 36

This block was allocated by thread 0x1DF4, and the stack trace (return addresses) at the time was:
40711A [System.pas][System][@GetMem$qqri][4755]
40910F [System.pas][System][TObject.NewInstance][16919]
40992E [System.pas][System][@ClassCreate$qqrpvzc][18252]
42FB07 [System.SysUtils.pas][System.SysUtils][Sysutils.Exception.Create][22886]
40F15C [System.pas][System][@IntfCast$qqrr44System.%DelphiInterface$17System.IInterface%x44System.%DelphiInterface$17System.IInterface%rx5_GUID][37358]
602D0C [DUnitX.TestRunner][Testrunner.TDUnitXTestRunner.Execute]
5E5F22 [DUnitX.WeakReference][Weakreference.TWeakReferencedObject._AddRef]
6296BB [TestInsight.DUnitX.pas][TestInsight.DUnitX][Dunitx.RunRegisteredTests$qqrv][149]
75300A [UnitTestRunner.pas][UnitTestRunner][TUnitTestRunner.RunRegisteredTests][136]
5114CA [UnitTestRegistration.pas][UnitTestRegistration][TUnitTestRegistration.RegisterTests][20]
7608B4 

The block is currently used for an object of class: ENoTestsRegistered

The allocation number is: 17539

Current memory dump of 256 bytes starting at pointer address 7F86B870:
6C 0A 5B 00 CC 77 92 7F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4C A1 EF 78
80 80 80 80 80 80 80 80 00 00 00 00 B1 BA 86 7F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
87 19 00 00 1A 71 40 00 EF AF 40 00 20 B2 40 00 F5 BF 40 00 73 8B 51 00 25 77 54 00 29 7B 54 00
8F EC 54 00 3F E2 54 00 52 03 55 00 FB CD 59 00 F4 1D 00 00 F4 1D 00 00 36 71 40 00 A9 B0 40 00
19 C6 40 00 3D C5 40 00 41 93 40 00 26 91 40 00 79 99 40 00 A0 C5 59 00 A7 92 40 00 E7 CA 59 00
A7 92 40 00 18 00 00 00 B0 04 02 00 BB E4 D7 85 84 1C 77 00 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 44 1B 28 7A 80 80 80 80 80 80 80 80 80 80 80 80 00 00 00 00 A1 AD 86 7F
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 6A 16 00 00 1A 71 40 00 0F 91 40 00 51 05 41 00
l  .  [  .  Ì  w  ’    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  L  ¡  ï  x
€  €  €  €  €  €  €  €  .  .  .  .  ±  º  †    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
‡  .  .  .  .  q  @  .  ï  ¯  @  .     ²  @  .  õ  ¿  @  .  s  ‹  Q  .  %  w  T  .  )  {  T  .
  ì  T  .  ?  â  T  .  R  .  U  .  û  Í  Y  .  ô  .  .  .  ô  .  .  .  6  q  @  .  ©  °  @  .
.  Æ  @  .  =  Å  @  .  A  “  @  .  &  ‘  @  .  y  ™  @  .     Å  Y  .  §  ’  @  .  ç  Ê  Y  .
§  ’  @  .  .  .  .  .  °  .  .  .  »  ä  ×  …  „  .  w  .  €  €  €  €  €  €  €  €  €  €  €  €
€  €  €  €  €  €  €  €  D  .  (  z  €  €  €  €  €  €  €  €  €  €  €  €  .  .  .  .  ¡  ­  †  
.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  j  .  .  .  .  q  @  .  .  ‘  @  .  Q  .  A  .

--------------------------------2019/5/7 13:10:33--------------------------------
A memory block has been leaked. The size is: 68

This block was allocated by thread 0x1DF4, and the stack trace (return addresses) at the time was:
40711A [System.pas][System][@GetMem$qqri][4755]
40AFEF [System.pas][System][@NewUnicodeString$qqri][24647]
40B220 [System.pas][System][@UStrFromPWCharLen$qqrr20System.UnicodeStringpbi][25325]
410A01 [System.pas][System][LoadResString$qqrp20System.TResStringRec][39405]
77053779 [Unknown function at RtlAllocateHeap]
76EEEE9A [Unknown function at RegCloseKey]
76EEDD47 [RegOpenKeyExInternalW]
76EEDE01 [RegOpenKeyExInternalW]
77053779 [Unknown function at RtlAllocateHeap]
76EEDBFC [RegOpenKeyExW]
77051F3E [RtlAllocateHeap]

The block is currently used for an object of class: UnicodeString

The allocation number is: 17538

Current memory dump of 256 bytes starting at pointer address 7F9277C0:
B0 04 02 00 01 00 00 00 16 00 00 00 4E 00 6F 00 20 00 54 00 65 00 73 00 74 00 20 00 46 00 69 00
78 00 74 00 75 00 72 00 65 00 73 00 20 00 66 00 6F 00 75 00 6E 00 64 00 00 00 B8 EF CE 3A 80 80
80 80 80 80 80 80 80 80 00 00 00 00 21 7C 92 7F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
97 25 00 00 89 71 40 00 DD D6 40 00 9B 95 40 00 1E D8 40 00 CA 7D 46 00 83 7E 46 00 0C B6 45 00
5C B6 45 00 13 87 46 00 D9 87 46 00 27 90 45 00 F4 1D 00 00 F4 1D 00 00 36 71 40 00 78 D9 40 00
82 C6 40 00 3D C5 40 00 41 93 40 00 26 91 40 00 79 99 40 00 5D B7 45 00 2D 91 40 00 79 99 40 00
A7 92 40 00 38 00 00 00 00 00 00 00 A5 A0 4C 85 84 1C 77 00 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
°  .  .  .  .  .  .  .  .  .  .  .  N  .  o  .     .  T  .  e  .  s  .  t  .     .  F  .  i  .
x  .  t  .  u  .  r  .  e  .  s  .     .  f  .  o  .  u  .  n  .  d  .  .  .  ¸  ï  Î  :  €  €
€  €  €  €  €  €  €  €  .  .  .  .  !  |  ’    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
—  %  .  .  ‰  q  @  .  Ý  Ö  @  .  ›  •  @  .  .  Ø  @  .  Ê  }  F  .  ƒ  ~  F  .  .  ¶  E  .
\  ¶  E  .  .  ‡  F  .  Ù  ‡  F  .  '    E  .  ô  .  .  .  ô  .  .  .  6  q  @  .  x  Ù  @  .
‚  Æ  @  .  =  Å  @  .  A  “  @  .  &  ‘  @  .  y  ™  @  .  ]  ·  E  .  -  ‘  @  .  y  ™  @  .
§  ’  @  .  8  .  .  .  .  .  .  .  ¥     L  …  „  .  w  .  €  €  €  €  €  €  €  €  €  €  €  €
€  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €  €

--------------------------------2019/5/7 13:10:33--------------------------------
This application has leaked memory. The small block leaks are (excluding expected leaks registered by pointer):

21 - 36 bytes: ENoTestsRegistered x 1
53 - 68 bytes: UnicodeString x 1

Note: Memory leak detail is logged to a text file in the same folder as this application. To disable this memory leak check, undefine "EnableMemoryLeakReporting".

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.