Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

723 lines
22 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. wsbtrak.cpp
  5. Abstract:
  6. Utility functions to keep track of run-time information.
  7. Author:
  8. Ron White [ronw] 5-Dec-1997
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "wsbguid.h"
  13. #if defined(WSB_TRACK_MEMORY)
  14. #define OBJECT_TABLE_SIZE 100
  15. #define POINTER_DATA_CURRENT 0
  16. #define POINTER_DATA_CUMULATIVE 2
  17. #define POINTER_DATA_MAX 1
  18. #define POINTER_DATA_SIZE 3
  19. #define POINTER_LIST_SIZE 1000
  20. typedef struct {
  21. GUID guid;
  22. LONG count;
  23. LONG total_count;
  24. LONG max_count;
  25. } OBJECT_TABLE_ENTRY;
  26. typedef struct {
  27. OLECHAR * guid_string;
  28. OLECHAR * name;
  29. GUID * pGuid;
  30. } OBJECT_NAME_ENTRY;
  31. typedef struct {
  32. LONG count;
  33. LONGLONG size;
  34. } POINTER_DATA_ENTRY;
  35. typedef struct {
  36. const void * addr;
  37. LONG order;
  38. ULONG size;
  39. int index; // Index into object table
  40. const char * filename;
  41. int linenum;
  42. } POINTER_LIST_ENTRY;
  43. // Module data
  44. #if defined(CRT_DEBUG_MEMORY)
  45. static _CrtMemState CrtMemState;
  46. #endif
  47. static OBJECT_TABLE_ENTRY object_table[OBJECT_TABLE_SIZE];
  48. static int object_table_count = 0;
  49. static POINTER_DATA_ENTRY pointer_data[POINTER_DATA_SIZE];
  50. static BOOL pointer_data_initialized = FALSE;
  51. static POINTER_LIST_ENTRY pointer_list[POINTER_LIST_SIZE];
  52. static int pointer_list_count = 0;
  53. static OBJECT_NAME_ENTRY object_name_table[] = {
  54. { L"{C03D4861-70D7-11d1-994F-0060976A546D}", L"CWsbStringPtr", NULL },
  55. { L"{C03D4862-70D7-11d1-994F-0060976A546D}", L"CWsbBstrPtr", NULL },
  56. { L"{A0FF1F42-237A-11D0-81BA-00A0C91180F2}", L"CWsbGuid", NULL },
  57. { L"{9C7D6F13-1562-11D0-81AC-00A0C91180F2}", L"CWsbOrderedCollection", NULL },
  58. { L"{46CE9EDE-447C-11D0-98FC-00A0C9058BF6}", L"CWsbDbKey", NULL },
  59. { L"{E707D9B2-4F89-11D0-81CC-00A0C91180F2}", L"CFsaServerNTFS", NULL },
  60. { L"{FCDC8671-7329-11d0-81DF-00A0C91180F2}", L"CFsaFilterNTFS", NULL },
  61. { L"{112981B3-1BA5-11D0-81B2-00A0C91180F2}", L"CFsaResourceNTFS", NULL },
  62. { L"{0B8B6F12-8B3A-11D0-990C-00A0C9058BF6}", L"CFsaPremigratedDb", NULL },
  63. { L"{14005FF1-8B4F-11d0-81E6-00A0C91180F2}", L"CFsaTruncatorNTFS", NULL },
  64. { L"{CECCB131-286D-11d1-993E-0060976A546D}", L"CFsaRecoveryRec", NULL },
  65. { L"{7CA819F2-8AAB-11D0-990C-00A0C9058BF6}", L"CFsaPremigratedRec", NULL },
  66. { L"{B2AD2931-84FD-11d0-81E4-00A0C91180F2}", L"CFsaFilterClientNTFS", NULL },
  67. { L"{F7860350-AA27-11d0-B16D-00A0C916F120}", L"CFsaPostIt", NULL },
  68. { L"{B2AD2932-84FD-11d0-81E4-00A0C91180F2}", L"CFsaFilterRecallNTFS", NULL },
  69. { L"{112981B2-1BA5-11D0-81B2-00A0C91180F2}", L"CFsaScanItemNTFS", NULL },
  70. { L"{7B22FF29-1AD6-11D0-81B1-00A0C91180F2}", L"CHsmActionManage", NULL },
  71. { L"{D9E04211-14D7-11d1-9938-0060976A546D}", L"CHsmActionOnResourcePostValidate", NULL },
  72. { L"{D9E04212-14D7-11d1-9938-0060976A546D}", L"CHsmActionOnResourcePreValidate", NULL },
  73. { L"{7B22FF24-1AD6-11D0-81B1-00A0C91180F2}", L"CHsmActionTruncate", NULL },
  74. { L"{D3AF5DB1-1DF8-11D0-81B6-00A0C91180F2}", L"CHsmActionUnmanage", NULL },
  75. { L"{7B22FF26-1AD6-11D0-81B1-00A0C91180F2}", L"CHsmActionValidate", NULL },
  76. { L"{AD40235F-00FC-11D0-819C-00A0C91180F2}", L"CHsmCritAlways", NULL },
  77. { L"{CFB04622-1C9F-11D0-81B4-00A0C91180F2}", L"CHsmCritManageable", NULL },
  78. { L"{7B22FF2C-1AD6-11D0-81B1-00A0C91180F2}", L"CHsmCritMigrated", NULL },
  79. { L"{7B22FF2D-1AD6-11D0-81B1-00A0C91180F2}", L"CHsmCritPremigrated", NULL },
  80. { L"{AD402346-00FC-11D0-819C-00A0C91180F2}", L"CHsmJob", NULL },
  81. { L"{AD402364-00FC-11D0-819C-00a0C91180F2}", L"CHsmJobContext", NULL },
  82. { L"{AD40234B-00FC-11D0-819C-00a0C91180F2}", L"CHsmJobDef", NULL },
  83. { L"{B8E1CD21-81D3-11d0-81E4-00A0C91180F2}", L"CHsmJobWorkItem", NULL },
  84. { L"{AB939AD0-6D67-11d0-9E2E-00A0C916F120}", L"CHsmManagedResource", NULL },
  85. { L"{8448dd80-7614-11d0-9e33-00a0c916f120}", L"CHsmManagedResourceCollection", NULL },
  86. { L"{BEA60F8A-7EBA-11d0-81E4-00A0C91180F2}", L"CHsmPhase", NULL },
  87. { L"{AD402350-00FC-11D0-819C-00A0C91180F2}", L"CHsmPolicy", NULL },
  88. { L"{AD40235A-00FC-11D0-819C-00A0C91180F2}", L"CHsmRule", NULL },
  89. { L"{C2E29801-B1BA-11d0-81E9-00A0C91180F2}", L"CHsmRuleStack", NULL },
  90. { L"{2D1E3156-25DE-11D0-8073-00A0C905F098}", L"CHsmServer", NULL },
  91. { L"{BEA60F80-7EBA-11d0-81E4-00A0C91180F2}", L"CHsmSession", NULL },
  92. { L"{FF67BB34-8430-11d0-81E4-00A0C91180F2}", L"CHsmSessionTotals", NULL },
  93. { L"{61F0B790-82D9-11d0-9E35-00A0C916F120}", L"CHsmStoragePool", NULL },
  94. { L"{23E45B60-C598-11d0-B16F-00A0C916F120}", L"CHsmWorkItem", NULL },
  95. { L"{247DF540-C558-11d0-B16F-00A0C916F120}", L"CHsmWorkQueue", NULL },
  96. { L"{450024A3-47D0-11D0-9E1E-00A0C916F120}", L"CBagHole", NULL },
  97. { L"{B13FA473-4E1B-11D0-9E22-00A0C916F120}", L"CBagInfo", NULL },
  98. { L"{F0D7AFE0-9026-11d0-9E3B-00A0C916F120}", L"CMediaInfo", NULL },
  99. { L"{768AD5A4-40C8-11D0-9E17-00A0C916F120}", L"CSegDB", NULL },
  100. { L"{37F704E6-3EF9-11D0-9E17-00A0C916F120}", L"CSegRec", NULL },
  101. { L"{BD030C00-000B-11D0-D0DD-00A0C9190459}", L"CMemIo Class", NULL },
  102. { L"{BD040C00-000B-11D0-D0DD-00A0C9190459}", L"CNtTapeIo Class", NULL },
  103. { L"{BD050C00-000B-11D0-D0DD-00A0C9190459}", L"CNtFileIo Class", NULL },
  104. { L"{FE37FA04-3729-11D0-8CF4-00A0C9190459}", L"RmsCartridge Class", NULL },
  105. { L"{FE37FA07-3729-11D0-8CF4-00A0C9190459}", L"RmsMediumChanger Class", NULL },
  106. { L"{FE37FA12-3729-11D0-8CF4-00A0C9190459}", L"RmsClient Class", NULL },
  107. { L"{FE37FA03-3729-11D0-8CF4-00A0C9190459}", L"RmsDriveClass Class", NULL },
  108. { L"{FE37FA05-3729-11D0-8CF4-00A0C9190459}", L"RmsDrive Class", NULL },
  109. { L"{FE37FA08-3729-11D0-8CF4-00A0C9190459}", L"RmsIEPort Class", NULL },
  110. { L"{FE37FA02-3729-11D0-8CF4-00A0C9190459}", L"RmsLibrary Class", NULL },
  111. { L"{FE37FA09-3729-11D0-8CF4-00A0C9190459}", L"RmsMediaSet Class", NULL },
  112. { L"{FE37FA13-3729-11D0-8CF4-00A0C9190459}", L"RmsNTMS Class", NULL },
  113. { L"{FE37FA11-3729-11D0-8CF4-00A0C9190459}", L"RmsPartition Class", NULL },
  114. { L"{FE37FA10-3729-11D0-8CF4-00A0C9190459}", L"RmsRequest Class", NULL },
  115. { L"{FE37FA01-3729-11D0-8CF4-00A0C9190459}", L"RmsServer Class", NULL },
  116. { L"{FE37FA14-3729-11D0-8CF4-00A0C9190459}", L"RmsSink Class", NULL },
  117. { L"{FE37FA06-3729-11D0-8CF4-00A0C9190459}", L"RmsStorageSlot Class", NULL },
  118. { L"{FE37FA15-3729-11D0-8CF4-00A0C9190459}", L"RmsTemplate Class", NULL },
  119. { NULL, NULL, NULL }
  120. };
  121. // Local functions
  122. static BOOL AddPointer(const void* addr, ULONG size, int index, const char * filename,
  123. int linenum);
  124. static OLECHAR* GuidToObjectName(const GUID& guid);
  125. static BOOL SubPointer(const void* addr, int index);
  126. // AddPointer - add a new pointer to the pointer list
  127. // Return FALSE on failure (list is full or pointer is already in list)
  128. static BOOL AddPointer(const void* addr, ULONG size, int index,
  129. const char * filename, int linenum)
  130. {
  131. int empty_slot = -1;
  132. int i;
  133. BOOL status = TRUE;
  134. if (!pointer_data_initialized) {
  135. pointer_data[POINTER_DATA_CURRENT].count = 0;
  136. pointer_data[POINTER_DATA_CURRENT].size = 0;
  137. pointer_data[POINTER_DATA_MAX].count = 0;
  138. pointer_data[POINTER_DATA_MAX].size = 0;
  139. pointer_data[POINTER_DATA_CUMULATIVE].count = 0;
  140. pointer_data[POINTER_DATA_CUMULATIVE].size = 0;
  141. pointer_data_initialized = TRUE;
  142. }
  143. for (i = 0; i < pointer_list_count; i++) {
  144. if (NULL == pointer_list[i].addr) {
  145. empty_slot = i;
  146. } else if (addr == pointer_list[i].addr) {
  147. WsbTraceAlways(OLESTR("AddPointer: address already in list: %lx (<%ls>, line: <%ld>\n"),
  148. (ULONG)addr, (OLECHAR *)filename, index);
  149. status = FALSE;
  150. break;
  151. }
  152. }
  153. if (i == pointer_list_count) {
  154. // Not in list. Is the list full?
  155. if (-1 == empty_slot && POINTER_LIST_SIZE == pointer_list_count) {
  156. WsbTraceAlways(OLESTR("AddPointer: pointer list is full: %lx\n"),
  157. (ULONG)addr);
  158. status = FALSE;
  159. } else if (-1 == empty_slot) {
  160. pointer_list_count++;
  161. } else {
  162. i = empty_slot;
  163. }
  164. }
  165. if (status) {
  166. pointer_list[i].addr = addr;
  167. pointer_list[i].size = size;
  168. pointer_list[i].index = index;
  169. pointer_list[i].filename = filename;
  170. pointer_list[i].linenum = linenum;
  171. pointer_data[POINTER_DATA_CURRENT].count++;
  172. pointer_data[POINTER_DATA_CURRENT].size += size;
  173. if (pointer_data[POINTER_DATA_CURRENT].count > pointer_data[POINTER_DATA_MAX].count) {
  174. pointer_data[POINTER_DATA_MAX].count = pointer_data[POINTER_DATA_CURRENT].count;
  175. }
  176. if (pointer_data[POINTER_DATA_CURRENT].size > pointer_data[POINTER_DATA_MAX].size) {
  177. pointer_data[POINTER_DATA_MAX].size = pointer_data[POINTER_DATA_CURRENT].size;
  178. }
  179. pointer_data[POINTER_DATA_CUMULATIVE].count++;
  180. pointer_data[POINTER_DATA_CUMULATIVE].size += size;
  181. pointer_list[i].order = pointer_data[POINTER_DATA_CUMULATIVE].count;
  182. }
  183. return(status);
  184. }
  185. // GuidToObjectName - convert a guid to an object name
  186. static OLECHAR* GuidToObjectName(const GUID& guid)
  187. {
  188. HRESULT hr = S_OK;
  189. int i;
  190. OLECHAR * name = NULL;
  191. try {
  192. // Need to do conversions from string to Guid?
  193. if (NULL == object_name_table[0].pGuid) {
  194. i = 0;
  195. while (object_name_table[i].guid_string) {
  196. GUID * pg = new GUID;
  197. WsbAffirmHr(WsbGuidFromString(object_name_table[i].guid_string,
  198. pg));
  199. object_name_table[i].pGuid = pg;
  200. i++;
  201. }
  202. }
  203. // See if this Guid is in the name table
  204. i = 0;
  205. while (object_name_table[i].guid_string) {
  206. if (guid == *object_name_table[i].pGuid) {
  207. name = object_name_table[i].name;
  208. break;
  209. }
  210. i++;
  211. }
  212. } WsbCatch(hr);
  213. return(name);
  214. }
  215. // SubPointer - remove a pointer from the pointer list
  216. // Return FALSE on failure (pointer is not in list or index doesn't match)
  217. static BOOL SubPointer(const void* addr, int index)
  218. {
  219. int i;
  220. BOOL status = TRUE;
  221. for (i = 0; i < pointer_list_count; i++) {
  222. if (addr == pointer_list[i].addr) {
  223. break;
  224. }
  225. }
  226. if (i == pointer_list_count) {
  227. WsbTraceAlways(OLESTR("SubPointer: pointer not found in list: %lx\n"),
  228. (ULONG)addr);
  229. status = FALSE;
  230. } else if (index != pointer_list[i].index) {
  231. WsbTraceAlways(OLESTR("SubPointer: type index doesn't match for pointer: %lx\n"),
  232. (ULONG)addr);
  233. WsbTraceAlways(OLESTR(", original type index = %d, new type index = %d\n"),
  234. pointer_list[i].index, index);
  235. status = FALSE;
  236. }
  237. if (status) {
  238. pointer_list[i].addr = NULL;
  239. pointer_data[POINTER_DATA_CURRENT].count--;
  240. pointer_data[POINTER_DATA_CURRENT].size -= pointer_list[i].size;
  241. }
  242. return(status);
  243. }
  244. HRESULT WsbObjectAdd(
  245. const GUID & guid,
  246. const void * addr
  247. )
  248. /*++
  249. Routine Description:
  250. Add another object to the object table
  251. Arguments:
  252. guid - Guid for the object type
  253. addr - Memory address of object
  254. Return Value:
  255. S_OK - Success
  256. --*/
  257. {
  258. HRESULT hr = S_OK;
  259. #if defined(CRT_DEBUG_MEMORY)
  260. // Set CRT debug flag
  261. static BOOL first = TRUE;
  262. if (first) {
  263. int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
  264. tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
  265. // Set the new state for the flag
  266. _CrtSetDbgFlag( tmpFlag );
  267. }
  268. #endif
  269. try {
  270. int i;
  271. // Reserve the first entry for non-objects and table overflow
  272. if (0 == object_table_count) {
  273. object_table[0].guid = GUID_NULL;
  274. object_table[0].count = 0;
  275. object_table[0].total_count = 0;
  276. object_table[0].max_count = 0;
  277. object_table_count = 1;
  278. }
  279. // Check in object type is already in table
  280. for (i = 0; i < object_table_count; i++) {
  281. if (guid == object_table[i].guid) break;
  282. }
  283. // Add a new entry if not (and there is room)
  284. if (i == object_table_count && i < OBJECT_TABLE_SIZE) {
  285. // WsbTraceAlways(OLESTR("WsbObjectAdd: new object, guid = %ls\n"),
  286. // WsbGuidAsString(guid));
  287. #if defined(CRT_DEBUG_MEMORY)
  288. WsbTraceAlways(OLESTR("WsbObjectAdd: _CrtCheckMemory = %ls\n"),
  289. WsbBoolAsString(_CrtCheckMemory()));
  290. #endif
  291. object_table[i].guid = guid;
  292. object_table[i].count = 0;
  293. object_table[i].total_count = 0;
  294. object_table[i].max_count = 0;
  295. object_table_count++;
  296. } else if (OBJECT_TABLE_SIZE == i) {
  297. // Use the first entry for everything else
  298. i = 0;
  299. }
  300. object_table[i].count++;
  301. object_table[i].total_count++;
  302. if (object_table[i].count > object_table[i].max_count) {
  303. object_table[i].max_count = object_table[i].count;
  304. }
  305. // Add to pointer list
  306. AddPointer(addr, 0, i, NULL, 0);
  307. } WsbCatch(hr);
  308. return(hr);
  309. }
  310. HRESULT WsbObjectSub(
  311. const GUID & guid,
  312. const void * addr
  313. )
  314. /*++
  315. Routine Description:
  316. Subtract an object from the object table
  317. Arguments:
  318. guid - Guid for the object type
  319. addr - Memory address of object
  320. Return Value:
  321. S_OK - Success
  322. --*/
  323. {
  324. HRESULT hr = S_OK;
  325. try {
  326. int i;
  327. // Find the object type in table
  328. for (i = 0; i < object_table_count; i++) {
  329. if (guid == object_table[i].guid) {
  330. // Allow count to go negative since this could indicate a problem
  331. object_table[i].count--;
  332. // Remove from pointer list
  333. SubPointer(addr, i);
  334. }
  335. }
  336. } WsbCatch(hr);
  337. return(hr);
  338. }
  339. HRESULT WsbObjectTracePointers(
  340. ULONG flags
  341. )
  342. /*++
  343. Routine Description:
  344. Dump the pointer list information to the trace file.
  345. Arguments:
  346. flags - WSB_OTP_ flags
  347. Return Value:
  348. S_OK - Success
  349. --*/
  350. {
  351. HRESULT hr = S_OK;
  352. try {
  353. int i;
  354. OLECHAR string[300];
  355. // Dump the current sequence number
  356. if (flags & WSB_OTP_SEQUENCE) {
  357. WsbTraceAlways(OLESTR("WsbObjectTracePointers: current sequence number = %ld\n"),
  358. pointer_data[POINTER_DATA_CUMULATIVE].count);
  359. }
  360. // Dump statistics
  361. if (flags & WSB_OTP_STATISTICS) {
  362. WsbTraceAlways(OLESTR("WsbObjectTracePointers: count, size\n"));
  363. WsbTraceAlways(OLESTR(" Current %8ld %12ls\n"),
  364. pointer_data[POINTER_DATA_CURRENT].count,
  365. WsbLonglongAsString(pointer_data[POINTER_DATA_CURRENT].size));
  366. WsbTraceAlways(OLESTR(" Maximum %8ld %12ls\n"),
  367. pointer_data[POINTER_DATA_MAX].count,
  368. WsbLonglongAsString(pointer_data[POINTER_DATA_MAX].size));
  369. WsbTraceAlways(OLESTR(" Cumulative %8ld %12ls\n"),
  370. pointer_data[POINTER_DATA_CUMULATIVE].count,
  371. WsbLonglongAsString(pointer_data[POINTER_DATA_CUMULATIVE].size));
  372. }
  373. // Dump non-NULL pointers
  374. if (flags & WSB_OTP_ALLOCATED) {
  375. WsbTraceAlways(OLESTR("WsbObjectTracePointers: allocated memory list (addr, size, order, name/GUID/file):\n"));
  376. for (i = 0; i < pointer_list_count; i++) {
  377. if (pointer_list[i].addr) {
  378. GUID guid = GUID_NULL;
  379. int index;
  380. OLECHAR * name = NULL;
  381. OLECHAR * pstr = NULL;
  382. index = pointer_list[i].index;
  383. if (index > 0 && index < object_table_count) {
  384. guid = object_table[index].guid;
  385. name = GuidToObjectName(guid);
  386. }
  387. if (0 == index) {
  388. wsprintf(string, OLESTR("%hs(%d)"), pointer_list[i].filename,
  389. pointer_list[i].linenum);
  390. pstr = string;
  391. } else if (name) {
  392. pstr = name;
  393. } else {
  394. wcscpy(string, WsbGuidAsString(guid));
  395. pstr = string;
  396. }
  397. WsbTraceAlways(OLESTR(" %8lx %8ld %8ld %ls\n"), pointer_list[i].addr,
  398. pointer_list[i].size, pointer_list[i].order, pstr);
  399. }
  400. }
  401. }
  402. #if defined(CRT_DEBUG_MEMORY)
  403. WsbTraceAlways(OLESTR("WsbObjectTrace: calling _CrtMemCheckpoint\n"));
  404. _CrtMemCheckpoint(&CrtMemState);
  405. WsbTraceAlways(OLESTR("WsbObjectTrace: MemState.lHighWaterCount = %ld, TotalCount = %ld\n"),
  406. CrtMemState.lHighWaterCount, CrtMemState.lTotalCount);
  407. WsbTraceAlways(OLESTR("WsbObjectTrace: MemState.blocks count & size\n"));
  408. WsbTraceAlways(OLESTR(" FREE %4ld %6ld\n"), CrtMemState.lCounts[_FREE_BLOCK],
  409. CrtMemState.lSizes[_FREE_BLOCK]);
  410. WsbTraceAlways(OLESTR(" NORMAL %4ld %6ld\n"), CrtMemState.lCounts[_NORMAL_BLOCK],
  411. CrtMemState.lSizes[_NORMAL_BLOCK]);
  412. WsbTraceAlways(OLESTR(" CRT %4ld %6ld\n"), CrtMemState.lCounts[_CRT_BLOCK],
  413. CrtMemState.lSizes[_CRT_BLOCK]);
  414. WsbTraceAlways(OLESTR(" IGNORE %4ld %6ld\n"), CrtMemState.lCounts[_IGNORE_BLOCK],
  415. CrtMemState.lSizes[_IGNORE_BLOCK]);
  416. WsbTraceAlways(OLESTR(" CLIENT %4ld %6ld\n"), CrtMemState.lCounts[_CLIENT_BLOCK],
  417. CrtMemState.lSizes[_CLIENT_BLOCK]);
  418. // WsbTraceAlways(OLESTR("WsbObjectTrace: calling _CrtMemDumpStatistics\n"));
  419. // _CrtMemDumpStatistics(&CrtMemState);
  420. // _CrtDumpMemoryLeaks();
  421. #endif
  422. } WsbCatch(hr);
  423. return(hr);
  424. }
  425. HRESULT WsbObjectTraceTypes(
  426. void
  427. )
  428. /*++
  429. Routine Description:
  430. Dump the object table information to the trace file.
  431. Arguments:
  432. None.
  433. Return Value:
  434. S_OK - Success
  435. --*/
  436. {
  437. HRESULT hr = S_OK;
  438. try {
  439. int i;
  440. WsbTraceAlways(OLESTR("WsbObjectTraceTypes: object table (GUID, total count, max count, current count, name):\n"));
  441. // Find the object type in table
  442. for (i = 0; i < object_table_count; i++) {
  443. OLECHAR * name;
  444. name = GuidToObjectName(object_table[i].guid);
  445. WsbTraceAlways(OLESTR(" %ls %6ld %5ld %5ld %ls\n"), WsbGuidAsString(object_table[i].guid),
  446. object_table[i].total_count, object_table[i].max_count,
  447. object_table[i].count, (name ? name : OLESTR("")));
  448. }
  449. } WsbCatch(hr);
  450. return(hr);
  451. }
  452. LPVOID WsbMemAlloc(ULONG cb, const char * filename, int linenum)
  453. /*++
  454. Routine Description:
  455. Debug tracking replacement for CoTaskAlloc.
  456. --*/
  457. {
  458. LPVOID p;
  459. p = CoTaskMemAlloc(cb);
  460. if (p) {
  461. AddPointer(p, cb, 0, filename, linenum);
  462. }
  463. return(p);
  464. }
  465. void WsbMemFree(LPVOID pv, const char *, int)
  466. /*++
  467. Routine Description:
  468. Debug tracking replacement for CoTaskFree.
  469. --*/
  470. {
  471. if (pv) {
  472. SubPointer(pv, 0);
  473. }
  474. CoTaskMemFree(pv);
  475. }
  476. LPVOID WsbMemRealloc(LPVOID pv, ULONG cb, const char * filename, int linenum)
  477. /*++
  478. Routine Description:
  479. Debug tracking replacement for CoTaskRealloc.
  480. --*/
  481. {
  482. LPVOID p;
  483. p = CoTaskMemRealloc(pv, cb);
  484. if (p) {
  485. if (pv) {
  486. SubPointer(pv, 0);
  487. }
  488. AddPointer(p, cb, 0, filename, linenum);
  489. }
  490. return(p);
  491. }
  492. BSTR WsbSysAllocString(const OLECHAR FAR * sz,
  493. const char * filename, int linenum)
  494. /*++
  495. Routine Description:
  496. Debug tracking replacement for SysAllocString
  497. --*/
  498. {
  499. BSTR b;
  500. b = SysAllocString(sz);
  501. if (b) {
  502. AddPointer(b, SysStringByteLen(b), 0, filename, linenum);
  503. }
  504. return(b);
  505. }
  506. BSTR WsbSysAllocStringLen(const OLECHAR FAR * sz,
  507. unsigned int cc, const char * filename, int linenum)
  508. /*++
  509. Routine Description:
  510. Debug tracking replacement for SysAllocStringLen
  511. --*/
  512. {
  513. BSTR b;
  514. b = SysAllocStringLen(sz, cc);
  515. if (b) {
  516. AddPointer(b, SysStringByteLen(b), 0, filename, linenum);
  517. }
  518. return(b);
  519. }
  520. void WsbSysFreeString(BSTR bs, const char *, int)
  521. /*++
  522. Routine Description:
  523. Debug tracking replacement for SysFreeString
  524. --*/
  525. {
  526. if (bs) {
  527. SubPointer(bs, 0);
  528. }
  529. SysFreeString(bs);
  530. }
  531. HRESULT WsbSysReallocString(BSTR FAR * pb, const OLECHAR FAR * sz,
  532. const char * filename, int linenum)
  533. /*++
  534. Routine Description:
  535. Debug tracking replacement for SysReallocString
  536. --*/
  537. {
  538. HRESULT hr;
  539. if (*pb) {
  540. SubPointer(*pb, 0);
  541. }
  542. hr = SysReAllocString(pb, sz);
  543. if (*pb) {
  544. AddPointer(*pb, SysStringByteLen(*pb), 0, filename, linenum);
  545. }
  546. return(hr);
  547. }
  548. HRESULT WsbSysReallocStringLen(BSTR FAR * pb,
  549. const OLECHAR FAR * sz, unsigned int cc, const char * filename, int linenum)
  550. /*++
  551. Routine Description:
  552. Debug tracking replacement for SysStringLen
  553. --*/
  554. {
  555. HRESULT hr;
  556. if (*pb) {
  557. SubPointer(*pb, 0);
  558. }
  559. hr = SysReAllocStringLen(pb, sz, cc);
  560. if (*pb) {
  561. AddPointer(*pb, SysStringByteLen(*pb), 0, filename, linenum);
  562. }
  563. return(hr);
  564. }
  565. #endif // WSB_TRACK_MEMORY