Opened 13 years ago

Closed 13 years ago

#3412 closed Bugs (fixed)

Memory leak in BOOST_CLASS_EXPORT registration

Reported by: Runar Undheim <r.undheim@…> Owned by: Robert Ramey
Milestone: Boost 1.41.0 Component: serialization
Version: Boost 1.41.0 Severity: Problem
Keywords: serialization memory leak Cc:

Description

Added example of code that will give memory leak. The code is tested with MSVC-8.0. When run in debug the program will show three memory leaks. If I set a break point in the void_caster_shortcut constructor the function is run once, but the destructor is never called.

#include <stdio.h>
#include <tchar.h>
#include <crtdbg.h>


#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/export.hpp>

class Base {
  friend class boost::serialization::access;
  template<class Archive>
  void serialize(Archive & ar, const unsigned int version) {  }

  virtual void vTest() { }
};

class Level1 : public Base {
  friend class boost::serialization::access;
  template<class Archive>
  void serialize(Archive & ar, const unsigned int version)
  { ar & boost::serialization::base_object<Base>(*this); }
};

class Level2 : public Level1 {
  friend class boost::serialization::access;
  template<class Archive>
  void serialize(Archive & ar, const unsigned int version)
  { ar & boost::serialization::base_object<Level1>(*this); }
};

BOOST_CLASS_EXPORT(Base)
BOOST_CLASS_EXPORT(Level1)
BOOST_CLASS_EXPORT(Level2)

int _tmain(int argc, _TCHAR* argv[])
{
  _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
  return 0;
}

Attachments (1)

MemLeakSerialization.cpp (1.5 KB ) - added by Runar Undheim <r.undheim@…> 13 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by Robert Ramey, 13 years ago

Resolution: fixed
Status: newclosed

I've fixed this on my own machine.

I don't know if it will get uploaded/tested in time for inclusion in 1.41.

Thanks for providing a good test case. It was very helpful.

Robert Ramey

by Runar Undheim <r.undheim@…>, 13 years ago

Attachment: MemLeakSerialization.cpp added

comment:2 by Runar Undheim <r.undheim@…>, 13 years ago

Resolution: fixed
Status: closedreopened
Version: Boost 1.40.0Boost 1.41.0

Some of the memory leaks are gone, but there are still some memory leaks left in the registration code. I have updated the example with Level3 and Level4 and get new leaks. See attached file. To make the code easier to debug it is possible to comment out BOOST_CLASS_EXPORT(Level4). Then you only get one leak.

comment:3 by Robert Ramey, 13 years ago

I've found this and fixed on my own machine. It will be checked into the trunk shortly.

I don't think I could have tracked this down without your test.

Robert Ramey

comment:4 by Robert Ramey, 13 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.