summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog-98b8
-rw-r--r--ace/Memory_Pool.cpp47
-rw-r--r--ace/Memory_Pool.h3
-rw-r--r--ace/Memory_Pool.i9
4 files changed, 51 insertions, 16 deletions
diff --git a/ChangeLog-98b b/ChangeLog-98b
index 36e78211eef..fd687e5bff1 100644
--- a/ChangeLog-98b
+++ b/ChangeLog-98b
@@ -1,5 +1,13 @@
Mon Aug 24 18:11:39 1998 Irfan Pyarali <irfan@cs.wustl.edu>
+ * ace/Memory_Pool.cpp (ACE_Local_Memory_Pool::release): This
+ memory pool uses "new" to create memory chunks for the Malloc
+ class. However, since it did not keep track of this memory,
+ these chunks were leaked.
+
+ The solution was to keep tarck of the chunks allocated and
+ delete them in release().
+
* ace/Object_Manager.cpp (~ACE_Object_Manager): Moved TSS cleanup
*before* Service_Config::close(). We need this to happen since
DLL related TSS objects need to get cleaned up *before* the DLL
diff --git a/ace/Memory_Pool.cpp b/ace/Memory_Pool.cpp
index 69e49eacf1d..072b1eaf0b8 100644
--- a/ace/Memory_Pool.cpp
+++ b/ace/Memory_Pool.cpp
@@ -8,6 +8,8 @@
#include "ace/Memory_Pool.i"
#endif /* __ACE_INLINE__ */
+#include "ace/Auto_Ptr.h"
+
ACE_RCSID(ace, Memory_Pool, "$Id$")
ACE_ALLOC_HOOK_DEFINE(ACE_Local_Memory_Pool)
@@ -30,15 +32,35 @@ ACE_Local_Memory_Pool::acquire (size_t nbytes,
{
ACE_TRACE ("ACE_Local_Memory_Pool::acquire");
rounded_bytes = this->round_up (nbytes);
- // ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%P|%t) acquiring more chunks, nbytes = %d, rounded_bytes = %d\n"), nbytes, rounded_bytes));
-
- void *cp = (void *) new char[rounded_bytes];
- if (cp == 0)
- ACE_ERROR_RETURN ((LM_ERROR, ASYS_TEXT ("(%P|%t) %u\n"), cp), 0);
+ ACE_Auto_Basic_Array_Ptr<char> cp = new char[rounded_bytes];
+
+ if (cp.get () == 0)
+ ACE_ERROR_RETURN ((LM_ERROR, ASYS_TEXT ("(%P|%t) new failed \n")), 0);
else
- // ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%P|%t) acquired more chunks, nbytes = %d, rounded_bytes = %d, new break = %d\n"), nbytes, rounded_bytes, cp));
- return cp;
+ {
+ int result = this->allocated_chunks_.insert (cp.get ());
+ if (result != 0)
+ ACE_ERROR_RETURN ((LM_ERROR, ASYS_TEXT ("(%P|%t) insertion into set failed\n")), 0);
+ }
+
+ return cp.release ();
+}
+
+int
+ACE_Local_Memory_Pool::release (void)
+{
+ ACE_TRACE ("ACE_Local_Memory_Pool::release");
+
+ // Zap the memory we allocated.
+ for (ACE_Unbounded_Set<char *>::iterator i = this->allocated_chunks_.begin ();
+ i != this->allocated_chunks_.end ();
+ ++i)
+ {
+ delete[] *i;
+ }
+
+ return 0;
}
ACE_ALLOC_HOOK_DEFINE(ACE_MMAP_Memory_Pool)
@@ -764,3 +786,14 @@ ACE_Shared_Memory_Pool::release (void)
return result;
}
#endif /* !ACE_LACKS_SYSV_SHMEM */
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class ACE_Auto_Basic_Array_Ptr<char *>;
+template class ACE_Unbounded_Set<char *>;
+template class ACE_Unbounded_Set_Iterator<char *>;
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+#pragma instantiate ACE_Auto_Basic_Array_Ptr<char *>
+#pragma instantiate ACE_Unbounded_Set<char *>
+#pragma instantiate ACE_Unbounded_Set_Iterator<char *>
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
+
diff --git a/ace/Memory_Pool.h b/ace/Memory_Pool.h
index 85b3d25cadd..9597dd61d28 100644
--- a/ace/Memory_Pool.h
+++ b/ace/Memory_Pool.h
@@ -291,6 +291,9 @@ public:
// Declare the dynamic allocation hooks.
protected:
+ ACE_Unbounded_Set<char *> allocated_chunks_;
+ // List of memory that we have allocated.
+
virtual size_t round_up (size_t nbytes);
// Implement the algorithm for rounding up the request to an
diff --git a/ace/Memory_Pool.i b/ace/Memory_Pool.i
index cd7ce978ab7..d116fea12e7 100644
--- a/ace/Memory_Pool.i
+++ b/ace/Memory_Pool.i
@@ -63,15 +63,6 @@ ACE_Local_Memory_Pool::round_up (size_t nbytes)
return ACE::round_to_pagesize (nbytes);
}
-// No-op for now...
-
-ACE_INLINE int
-ACE_Local_Memory_Pool::release (void)
-{
- ACE_TRACE ("ACE_Local_Memory_Pool::release");
- return 0;
-}
-
#if !defined (ACE_LACKS_SYSV_SHMEM)
// Implement the algorithm for rounding up the request to an
// appropriate chunksize.