Changeset 1077 for trunk/dll/fortify.c
- Timestamp:
- Jul 18, 2008, 8:11:54 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/fortify.c
r1072 r1077 43 43 /* 06 May 08 SHL Rework scope logic to be MT capable 44 44 26 May 08 SHL Show TID for leaking scope 45 17 Jul 08 SHL Add Fortify_SetOwner Fortify_ChangeOwner 45 17 Jul 08 SHL Add Fortify_SetOwner Fortify_ChangeOwner Fortify_ChangeScope 46 18 Jul 08 SHL Add FORTIFY_VERBOSE_SCOPE_ENTER_EXIT 46 47 */ 47 48 … … 177 178 #ifdef MT_SCOPES 178 179 static unsigned volatile st_cOrdinals; // Number of known threads 179 static unsigned volatilechar* st_pScopes; // Scope level of blocks allocated by thread180 static unsigned volatilelong* st_pOwners; // Owner of blocks allocated by thread180 static volatile unsigned char* st_pScopes; // Scope level of blocks allocated by thread 181 static volatile unsigned long* st_pOwners; // Owner of blocks allocated by thread 181 182 #else 182 183 static unsigned char st_Scope = 0; … … 997 998 FORTIFY_UNLOCK(); 998 999 } 999 return(++st_pScopes[ordinal]); 1000 i = ++st_pScopes[ordinal]; 1001 # ifdef FORTIFY_VERBOSE_SCOPE_ENTER_EXIT 1002 sprintf(st_Buffer, 1003 "Fortify: Entering scope %u in TID %u at %s.%lu\n", 1004 i, ordinal, 1005 file, line); // 26 May 08 SHL 1006 st_Output(st_Buffer); 1007 # endif 1008 return(i); 1000 1009 #else 1001 1010 return(++st_Scope); … … 1025 1034 // Complain on leave without enter 06 May 08 SHL 1026 1035 ordinal = Get_TID_Ordinal(); 1027 if (ordinal < st_cOrdinals && st_pScopes[ordinal] > 0) 1036 if (ordinal < st_cOrdinals && st_pScopes[ordinal] > 0) { 1028 1037 st_pScopes[ordinal]--; 1038 } 1029 1039 else { 1030 1040 sprintf(st_Buffer, 1031 "\nFortify: attempting to leave scope before enter at %s.%lu in TID %u\n",1032 file, line, ordinal); // 26 May 08 SHL1041 "\nFortify: Attempting to leave scope before enter in TID %u at %s.%lu\n", 1042 ordinal, file, line); // 26 May 08 SHL 1033 1043 st_Output(st_Buffer); 1034 1044 } … … 1037 1047 st_Scope--; 1038 1048 else { 1039 sprintf(st_Buffer, "\nFortify: attempting to leave scope before enter at %s.%lu\n", file, line);1049 sprintf(st_Buffer, "\nFortify: Attempting to leave scope before enter at %s.%lu\n", file, line); 1040 1050 st_Output(st_Buffer); 1041 1051 } … … 1054 1064 #ifdef MT_SCOPES 1055 1065 sprintf(st_Buffer, 1056 "\nFortify: Memory leak detected leaving scope at %s.%lu in TID %u\n", 1057 file, line, ordinal); 1066 "\nFortify: Memory leak detected leaving scope %d in TID %u at %s.%lu\n", 1067 ordinal < st_cOrdinals ? st_pScopes[ordinal] + 1 : 0, 1068 ordinal, 1069 file, line); 1058 1070 #else 1059 1071 sprintf(st_Buffer, "\nFortify: Memory leak detected leaving scope at %s.%lu\n", file, line); … … 1078 1090 st_Output(st_Buffer); 1079 1091 } 1092 # ifdef FORTIFY_VERBOSE_SCOPE_ENTER_EXIT 1093 else { 1094 sprintf(st_Buffer, 1095 "Fortify: Leaving scope %u in TID %u at %s.%lu\n", 1096 ordinal < st_cOrdinals ? st_pScopes[ordinal] + 1 : 0, 1097 ordinal, 1098 file, line); // 26 May 08 SHL 1099 st_Output(st_Buffer); 1100 } 1101 # endif 1080 1102 1081 1103 #ifdef FORTIFY_TRACK_DEALLOCATED_MEMORY … … 2430 2452 if (ordinal >= st_cOrdinals) { 2431 2453 // Expand arrays 2432 2433 2454 unsigned i; 2455 unsigned c; 2434 2456 FORTIFY_LOCK(); 2435 2457 i = st_cOrdinals; … … 2450 2472 /** 2451 2473 * Take ownership of block allocated by some other thread 2452 * Allows scope enter/exit logic to correctly report leaks in 2474 * Allows scope enter/exit logic to correctly report leaks in 2453 2475 * cross thread allocations 2454 * @param p Void is pointto block allocated by Fortify2476 * @param pBlock points to block allocated by Fortify 2455 2477 */ 2456 2478 … … 2466 2488 h->Scope = ordinal < st_cOrdinals ? st_pScopes[ordinal] : 0; 2467 2489 h->Owner = ordinal; // Take ownership 2490 st_MakeHeaderValid(h); 2491 } 2492 2493 /** 2494 * Adjust scope level of allocated block 2495 * Allows scope enter/exit logic to correctly report leaks in 2496 * window procedure related allocations 2497 * @param pBlock points to block allocated by Fortify 2498 */ 2499 2500 void Fortify_ChangeScope(void *pBlock, int delta) 2501 { 2502 unsigned char *ptr = (unsigned char *)pBlock - 2503 FORTIFY_HEADER_SIZE - 2504 FORTIFY_ALIGNED_BEFORE_SIZE; 2505 struct Header *h = (struct Header *)ptr; 2506 h->Scope += delta; 2507 st_MakeHeaderValid(h); 2468 2508 } 2469 2509
Note:
See TracChangeset
for help on using the changeset viewer.