Permalink
Browse files

Fixed memory allocated issue exposed by BOOST pool_alloc

  • Loading branch information...
1 parent cca9397 commit 7b2978ae8056d2c9635ced7e4fdfa4ceddcd853f @saleyn committed Jul 31, 2012
@@ -81,6 +81,7 @@ namespace marshal {
, public Alloc::template rebind<T>::other
{
typedef typename Alloc::template rebind<T>::other base_t;
+ typedef typename Alloc::template rebind<blob<T,Alloc> >::other blob_alloc_t;
atomic<int> m_rc;
const size_t m_size;
@@ -134,20 +135,23 @@ namespace marshal {
return *reinterpret_cast<const Alloc*>(this);
}
+ static blob_alloc_t& get_blob_alloc() {
+ static blob_alloc_t s_alloc;
+ return s_alloc;
+ }
+
/// This method overrides the new() operator for this class
/// so that the blob memory is taken from the Alloc allocator.
static void* operator new(size_t sz) {
BOOST_ASSERT(sz == sizeof(blob<T,Alloc>));
- typename Alloc::template rebind<blob<T,Alloc> >::other a;
- return a.allocate(sz);
+ return get_blob_alloc().allocate(1);
}
/// This method overrides the new() operator for this class
/// so that the blob memory is released to the Alloc allocator.
static void operator delete(void* p, size_t sz) {
BOOST_ASSERT(sz == sizeof(blob<T,Alloc>));
- typename Alloc::template rebind<blob<T,Alloc> >::other a;
- a.deallocate(static_cast<blob<T,Alloc>*>(p), sz);
+ get_blob_alloc().deallocate(static_cast<blob<T,Alloc>*>(p), 1);
}
};
@@ -90,7 +90,7 @@ class list : protected alloc_base<cons<Alloc>, Alloc> {
if (l_header->alloc_size > 0 && l_header->size > l_header->alloc_size)
for (cons_t* p = (l_header->head + l_header->alloc_size - 1)->next, *q; p; p = q) {
q = p->next;
- this->get_t_allocator().deallocate(p, sizeof(cons_t));
+ this->get_t_allocator().deallocate(p, 1);
}
}
m_blob->free();
View
@@ -1,13 +1,14 @@
bin_PROGRAMS = test_eterm test_perf
+AM_CXXFLAGS = -I. -I$(srcdir)/../include $(BOOST_CPPFLAGS) \
+ -I$(ERLANG_LIB_DIR_erl_interface)/include \
+ -I$(ERLANG_LIB_DIR_erl_interface)/src
+
test_eterm_SOURCES = test_eterm.cpp test_eterm_encode.cpp \
test_eterm_format.cpp test_eterm_match.cpp \
test_eterm_pool.cpp test_eterm_refc.cpp \
test_mailbox.cpp test_node.cpp
-test_eterm_CPPFLAGS = -I$(srcdir)/../include $(BOOST_CPPFLAGS) \
- -I$(ERLANG_LIB_DIR_erl_interface)/include \
- -I$(ERLANG_LIB_DIR_erl_interface)/src \
- -DBOOST_TEST_DYN_LINK -g -O$(if $(optimize),3 -DBOOST_DISABLE_ASSERTS,0) \
+test_eterm_CPPFLAGS = -DBOOST_TEST_DYN_LINK -g -O$(if $(optimize),3 -DBOOST_DISABLE_ASSERTS,0) \
$(if $(debug),-DEIXX_DEBUG)
test_eterm_LDFLAGS = $(BOOST_LDFLAGS) \
-L$(ERLANG_LIB_DIR_erl_interface)/lib
@@ -16,10 +17,7 @@ test_eterm_LDADD = -L../src/.libs -leixx -lei \
$(BOOST_THREAD_LIB)
test_perf_SOURCES = test_perf.cpp
-test_perf_CPPFLAGS = -I$(srcdir)/../include $(BOOST_CPPFLAGS) \
- -I$(ERLANG_LIB_DIR_erl_interface)/include \
- -I$(ERLANG_LIB_DIR_erl_interface)/src \
- -O$(if $(optimize),3 -DBOOST_DISABLE_ASSERTS,0)
+test_perf_CPPFLAGS = -O$(if $(optimize),3 -DBOOST_DISABLE_ASSERTS,0)
test_perf_LDFLAGS = -L$(ERLANG_LIB_DIR_erl_interface)/lib $(BOOST_LDFLAGS)
test_perf_LDADD = -L../src/.libs -leixx $(BOOST_SYSTEM_LIB)
View
@@ -24,8 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define BOOST_TEST_MODULE test_eterm
#include <boost/test/unit_test.hpp>
-//#include <eixx/alloc_pool_st.hpp>
-#include <eixx/alloc_std.hpp>
+#include "test_alloc.hpp"
#include <eixx/eixx.hpp>
#include <set>
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <boost/test/unit_test.hpp>
-#include <eixx/alloc_std.hpp>
+#include "test_alloc.hpp"
#include <eixx/eixx.hpp>
using namespace eixx;
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***** END LICENSE BLOCK *****
*/
#include <boost/test/unit_test.hpp>
-#include <eixx/alloc_pool_st.hpp>
+#include "test_alloc.hpp"
#include <eixx/eixx.hpp>
#include <eixx/marshal/eterm_format.hpp>
@@ -23,9 +23,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <boost/test/unit_test.hpp>
-#include <boost/pool/pool_alloc.hpp>
#include <boost/bind.hpp>
-#include <eixx/alloc_pool_st.hpp>
+#include "test_alloc.hpp"
#include <eixx/eixx.hpp>
using namespace EIXX_NAMESPACE;
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***** END LICENSE BLOCK *****
*/
#include <boost/test/unit_test.hpp>
-#include <eixx/alloc_pool_st.hpp>
+#include "test_alloc.hpp"
#include <eixx/eixx.hpp>
using namespace EIXX_NAMESPACE;
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***** END LICENSE BLOCK *****
*/
#include <boost/test/unit_test.hpp>
-#include <eixx/alloc_pool_st.hpp>
+#include "test_alloc.hpp"
#include <eixx/marshal/eterm.hpp>
using namespace EIXX_NAMESPACE;
@@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <boost/test/unit_test.hpp>
-#include <eixx/alloc_std.hpp>
+#include "test_alloc.hpp"
#include <eixx/eixx.hpp>
using namespace eixx;
View
@@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <boost/test/unit_test.hpp>
-#include <eixx/alloc_std.hpp>
+#include "test_alloc.hpp"
#include <eixx/eixx.hpp>
using namespace eixx;
View
@@ -1,5 +1,4 @@
-//#include <eixx/alloc_pool_st.hpp>
-#include <eixx/alloc_std.hpp>
+#include "test_alloc.hpp"
#include <eixx/eixx.hpp>
#include <stdio.h>
#include <sys/time.h>

0 comments on commit 7b2978a

Please sign in to comment.