Artifacts Associated With Ticket 2286247
Ticket change [4a5cb2d40a] (rid 126525) by nobody on 2008-11-14 20:51:42:
- assignee initialized to: "msofer"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The cleanup function Tcl_FinalizeEncodingSubsystem (tclEncoding.c) causes Purify FMR and FMW errors when exiting tcl/tk. The problem occurs when an escape-driven encoding gets freed after its associated sub-encodings have been freed. In that case, the escape-driven encoding tries to free its sub-encodings, causing memory problems. To address this problem, one must guarantee that the escape-driven encodings are freed before their sub-encodings. This could be done by using a stack / linked list (instead of a hash table) to store the encodings in the order they are created. The encodings would have to be deleted in the reverse order. The other solution (implemented in the code below) is to traverse the hash table multiple times and to delete the escape-driven encodings first. This solution is more self-contained and involves less change in the code than using a different data structure. void TclFinalizeEncodingSubsystem() { Tcl_HashSearch search; Tcl_HashEntry *hPtr; /* SYNOPSYS_START */ #ifndef TCL_ORIG int found = 1; #endif /* SYNOPSYS_END */ Tcl_MutexLock(&encodingMutex); encodingsInitialized = 0; FreeEncoding(systemEncoding); /* SYNOPSYS_START */ #ifndef TCL_ORIG /* * Free all escape-driven encodings first. This assumes that escape-driven * encodings do not reference other escape-driven encodings. */ while (found) { found = 0; hPtr = Tcl_FirstHashEntry(&encodingTable, &search); while (hPtr != NULL) { Encoding *encodingPtr; encodingPtr = (Encoding *) Tcl_GetHashValue(hPtr); if (encodingPtr->freeProc == EscapeFreeProc) { /* This is an escape-driven encoding. */ FreeEncoding((Tcl_Encoding) encodingPtr); found = 1; break; /* Let's traverse the hash table again from the start to * find another escape-driven encoding (possibly the same * one if it has not been freed, its ref count not having * reached zero yet). The reason for this multi-pass * approach is that freeing an encoding means deleting * its hash entry and we cannot do that while traversing * the hash table with Tcl_NextHashEntry. */ } hPtr = Tcl_NextHashEntry(&search); } } /* What remains in the hash table are non-escape-driven encodings. * Let's free them. */ #endif /* SYNOPSYS_END */ hPtr = Tcl_FirstHashEntry(&encodingTable, &search); while (hPtr != NULL) { /* * Call FreeEncoding instead of doing it directly to handle refcounts * like escape encodings use. [Bug #524674] * Make sure to call Tcl_FirstHashEntry repeatedly so that all * encodings are eventually cleaned up. */ FreeEncoding((Tcl_Encoding) Tcl_GetHashValue(hPtr)); hPtr = Tcl_FirstHashEntry(&encodingTable, &search); } Tcl_DeleteHashTable(&encodingTable); Tcl_MutexUnlock(&encodingMutex); } - foundin initialized to: "None"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "10. Objects"
- title initialized to: "Encoding cleanup causes memory errors when exiting"
- type initialized to: "Bug"
Ticket change [7d1e091693] (rid 97192) by dgp on 2008-11-16 10:38:40:
- assignee changed to: "dgp"
- closedate changed to: "2008-11-16T03:38:40"
- closer changed to: "dgp"
- icomment:
Please report the version(s) of Tcl where you see this issue.
- login: "dgp"
- mimetype: "text/plain"
- status changed to: "Pending"
- username: "dgp"
Ticket change [4016c99899] (rid 121566) by sf-robot on 2008-12-01 09:20:07:
- closedate changed to: "2008-12-01T02:20:07"
- closer changed to: "sf-robot"
- icomment:
This Tracker item was closed automatically by the system. It was previously set to a Pending status, and the original submitter did not respond within 14 days (the time period specified by the administrator of this Tracker).
- login: "sf-robot"
- mimetype: "text/plain"
- status changed to: "Closed"
- username: "sf-robot"