[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Thread documentation error and segfault
From: |
Idar Tollefsen |
Subject: |
Thread documentation error and segfault |
Date: |
Fri, 07 May 2004 12:54:13 +0200 |
User-agent: |
Mozilla Thunderbird 0.5 (Macintosh/20040208) |
Hey,
I have found what I believe is an error in the documentation of the Thread class
and what I believe is a bug in the same class.
The documentation for Thread::final
(http://www.gnu.org/software/commoncpp/docs/refman/html/class_thread.html#b2),
and examples shown for how to use the thread explains that a detached thread can
do "delete this" in it's final method, if it exists right away. I've also seen
examples in the documentation saying one could set "this" to 0 (with memset)
after "delete this".
Not so. This was the case for 2.0.13, but not for 1.1.x (not sure when the
change happened). In Thread::close(), final() is one of the first functions
called. However, the last two lines of that functions is:
if (detached)
delete this;
which of course will fail of you already did this in your own thread's final().
I like this new approach better than the old one, but the documentation needs an
update to reflect this change.
The bug I believe I've found is in ThreadImpl::ThreadDestructor(), where the
line
if (th->priv->_type == threadTypeDummy)
segfaults.
I haven't investigated why, or what "priv" is, but the attached patch (which
checks whether or not "th" and "priv" is NULL before trying to access them)
fixed the problem. I have checked that the patch doesn't produce memory leaks,
so the thread is apparently already deleted when it reaches this function.
Sincerely,
Idar Tollefsen
--- src/thread.cpp.orig Fri Mar 12 16:39:49 2004
+++ src/thread.cpp Fri Apr 16 13:27:44 2004
@@ -1023,7 +1023,9 @@
{
if (!th || th == DUMMY_INVALID_THREAD)
return;
- if (th->priv->_type == threadTypeDummy)
+
+ if ((th != NULL) && (th->priv != NULL) &&
+ (th->priv->_type == threadTypeDummy))
delete th;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Thread documentation error and segfault,
Idar Tollefsen <=