summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbala <balanatarajan@users.noreply.github.com>2004-11-05 18:30:36 +0000
committerbala <balanatarajan@users.noreply.github.com>2004-11-05 18:30:36 +0000
commit2737bf234dca5428d6d05c656d4dd5f348a6e58b (patch)
treedf2d74111f8efd579a30eaa13589b6185fbf364e
parentca4cb6c60320902130e9a34ba3035cb6f7a9ca00 (diff)
downloadATCD-2737bf234dca5428d6d05c656d4dd5f348a6e58b.tar.gz
ChageLogTag:Fri Nov 5 18:11:41 2004 Balachandran Natarajan <bala@dre.vanderbilt.edu>
-rw-r--r--ChangeLog26
-rw-r--r--ace/Base_Thread_Adapter.h26
-rw-r--r--ace/OS_NS_Thread.cpp18
3 files changed, 50 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 11c50b08ef9..30ceb87e347 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+Fri Nov 5 18:11:41 2004 Balachandran Natarajan <bala@dre.vanderbilt.edu>
+
+ * ace/OS_NS_Thread.cpp (thr_create):
+
+ Fixed memory leak that were caused due to allocated
+ <thread_args> not being deleted whenever there is an error. Got
+ around this problem by using an auto_ptr, and releasing the
+ pointer when thr_create () is successful. Thanks to Gary Maxey
+ for reporting the problem.
+
+ * ace/Base_Thread_Adapter.h (ACE_Base_Thread_Adapter):
+
+ Moved the destructor to be public and the constructor to be
+ private. Making the destructor seems to have more downsides like
+ the one above (which basically prevented us from using
+ auto_ptr's).
+
Fri Nov 5 16:14:12 UTC 2004 Martin Corino <mcorino@remedy.nl>
* ace/OS_NS_stdlib.cpp:
@@ -17,10 +34,11 @@ Fri Nov 5 15:36:12 UTC 2004 Martin Corino <mcorino@remedy.nl>
* bin/MakeProjectCreator/templates/gnu.mpd:
* include/makeinclude/rules.bin.GNU:
- Changes to support VxWorks 5.5.1 linking (both DIAB and GNU toolchains).
- With VxWorks 5.5.1 linking is done based on rules/targets defined in the
- makefile configuration provided with the VxWorks toolset which is embedded
- in the ACE/TAO structure through the platform_macros.
+ Changes to support VxWorks 5.5.1 linking (both DIAB and GNU
+ toolchains). With VxWorks 5.5.1 linking is done based on
+ rules/targets defined in the makefile configuration provided
+ with the VxWorks toolset which is embedded in the ACE/TAO
+ structure through the platform_macros.
Fri Nov 5 15:30:12 UTC 2004 Martin Corino <mcorino@remedy.nl>
diff --git a/ace/Base_Thread_Adapter.h b/ace/Base_Thread_Adapter.h
index 5ca62ae6cbf..24cd5b8c677 100644
--- a/ace/Base_Thread_Adapter.h
+++ b/ace/Base_Thread_Adapter.h
@@ -79,16 +79,8 @@ protected:
class ACE_Export ACE_Base_Thread_Adapter
{
public:
- /// Constructor.
- ACE_Base_Thread_Adapter (ACE_THR_FUNC user_func,
- void *arg,
- ACE_THR_C_FUNC entry_point = (ACE_THR_C_FUNC) ace_thread_adapter,
- ACE_OS_Thread_Descriptor *td = 0
-# if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
- , ACE_SEH_EXCEPT_HANDLER selector = 0
- , ACE_SEH_EXCEPT_HANDLER handler = 0
-# endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
- );
+
+ virtual ~ACE_Base_Thread_Adapter (void);
/// Virtual method invoked by the thread entry point.
virtual ACE_THR_FUNC_RETURN invoke (void) = 0;
@@ -113,10 +105,16 @@ public:
static ACE_OS_Thread_Descriptor *thr_desc_log_msg (void);
protected:
- /// Destructor, making it private ensures that objects of this class
- /// are allocated on the heap.
- virtual ~ACE_Base_Thread_Adapter (void);
-
+ /// Constructor.
+ ACE_Base_Thread_Adapter (ACE_THR_FUNC user_func,
+ void *arg,
+ ACE_THR_C_FUNC entry_point = (ACE_THR_C_FUNC) ace_thread_adapter,
+ ACE_OS_Thread_Descriptor *td = 0
+# if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
+ , ACE_SEH_EXCEPT_HANDLER selector = 0
+ , ACE_SEH_EXCEPT_HANDLER handler = 0
+# endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
+ );
/// Inherit the logging features if the parent thread has an
/// <ACE_Log_Msg>.
void inherit_log_msg (void);
diff --git a/ace/OS_NS_Thread.cpp b/ace/OS_NS_Thread.cpp
index 44ceeef85a2..22306b89f9b 100644
--- a/ace/OS_NS_Thread.cpp
+++ b/ace/OS_NS_Thread.cpp
@@ -18,6 +18,7 @@ ACE_RCSID (ace,
#include "ace/OS_NS_ctype.h"
#include "ace/Log_Msg.h" // for ACE_ASSERT
// This is necessary to work around nasty problems with MVS C++.
+#include "ace/Auto_Ptr.h"
extern "C" void
ace_mutex_lock_cleanup_adapter (void *args)
@@ -2238,7 +2239,6 @@ ACE_OS::thr_create (ACE_THR_FUNC func,
ACE_Base_Thread_Adapter *thread_args;
if (thread_adapter == 0)
-
#if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
ACE_NEW_RETURN (thread_args,
ACE_OS_Thread_Adapter (func, args,
@@ -2256,6 +2256,13 @@ ACE_OS::thr_create (ACE_THR_FUNC func,
else
thread_args = thread_adapter;
+ auto_ptr <ACE_Base_Thread_Adapter> auto_thread_args;
+
+ if (thread_adapter == 0)
+ ACE_AUTO_PTR_RESET (auto_thread_args,
+ thread_args,
+ ACE_Base_Thread_Adapter);
+
#if defined (ACE_HAS_THREADS)
// *** Set Stack Size
@@ -2768,6 +2775,7 @@ ACE_OS::thr_create (ACE_THR_FUNC func,
# endif /* ACE_NEEDS_LWP_PRIO_SET */
# endif /* sun && ACE_HAS_ONLY_SCHED_OTHER */
+ auto_thread_args.release ();
return result;
# elif defined (ACE_HAS_STHREADS)
int result;
@@ -2810,6 +2818,7 @@ ACE_OS::thr_create (ACE_THR_FUNC func,
}
}
}
+ auto_thread_args.release ();
return result;
# elif defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (stack);
@@ -2885,7 +2894,10 @@ ACE_OS::thr_create (ACE_THR_FUNC func,
::CloseHandle (tmp_handle);
if (*thr_handle != 0)
- return 0;
+ {
+ auto_thread_args.release ();
+ return 0;
+ }
else
ACE_FAIL_RETURN (-1);
/* NOTREACHED */
@@ -2952,6 +2964,7 @@ ACE_OS::thr_create (ACE_THR_FUNC func,
// store the task id in the handle and return success
*thr_handle = tid;
+ auto_thread_args.release ();
return 0;
# elif defined (VXWORKS)
@@ -3049,6 +3062,7 @@ ACE_OS::thr_create (ACE_THR_FUNC func,
if (thr_handle)
*thr_handle = tid;
+ auto_thread_args.release ();
return 0;
}