|
2009-07-23
| ||
| 17:23 | • Closed ticket [2820349fff]: Tcl_ThreadQueueEvent can lead to memory leaks pl... artifact: f6d05905c0 user: mistachkin | |
| 16:59 | • Ticket [2820349fff]: 4 changes artifact: 043e2fd1b5 user: mistachkin | |
| 15:15 | • Ticket [2820349fff]: 2 changes artifact: 6216cbe21c user: mistachkin | |
| 15:15 | • Ticket [2820349fff]: 4 changes artifact: af90303fd0 user: mistachkin | |
|
2009-07-12
| ||
| 12:15 | • New ticket [2820349fff]. artifact: 57ddd2c8ad user: flatworm | |
Tcl_ThreadQueueEvent can lead to memory leaks
Closed / Fixed2820349fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-07-12 12:15:44
Tcl_ThreadQueueEvent() only calls QueueEvent() which actually adds the event to the specified notifier's queue if such notifier was found, that is, if there is a notifier bound to the thread specified in the call.
As the specification states that after a call to Tcl_ThreadQueueEvent() the event's memory will be owned by the approptiate notifier, and the function does not return any information to the caller about whether the event was delivered or not, then if the target thread does not exist, the event memory will be lost.
Since this function is a part of the public API (and therefore can be called with arbitrary arguments) the possibility of the non-existing target thread is possible.
I think that turning
if (tsdPtr) {
QueueEvent(tsdPtr, evPtr, position);
}
into
if (tsdPtr) {
QueueEvent(tsdPtr, evPtr, position);
} else {
ckfree((char*) evPtr);
}
would fulfill the contract about the event's memory handling.
mistachkinplain2009-07-23 15:15:43
Nice catch. The comments clearly state that the memory pointed to by evPtr "becomes the property of the event queue. It will be freed after the event has been handled" (i.e. currently, if the event is never handled then the memory is never freed). Upping priority.
mistachkin Ticket [2820349fff]: 2 changes
[History diff]2009-07-23 15:15:44
mistachkinplain2009-07-23 16:59:56
This bug appears to exist as far back as 8.1. I plan to backport the fix to 8.4 and 8.5.
mistachkinplain2009-07-23 17:23:20
allow_comments - 1 Fix committed to HEAD and backported to the 8.4 and 8.5 branches.
Log in (anonymous is fine) to add a comment.