Q:

C++ destructor runtime error: failed to munmap

I've defined a class called ClusterSet that just has one field, called clusters: 
class ClusterSet {
   std::map<std::string, std::map<std::string, float>* > clusters;

   public:
      typedef std::map<std::string, std::map<std::string, float> *>::iterator iterator;
      typedef std::map<std::string, std::map<std::string, float> *>::const_iterator const_iterator;

      iterator begin() { return clusters.begin(); }
      const_iterator begin() const { return clusters.begin(); }
      iterator end() { return clusters.end(); }
      const_iterator end() const { return clusters.end(); }

      void create_cluster(std::string representative);
      void add_member(std::string representative, std::string member, float similarity);
      int write_to_file(std::string outputfile);
      int size();
      ~ClusterSet();
};

In my create_cluster method, I use new to allocate memory for the inner map, and store this pointer in clusters.  I defined a destructor so that I can deallocate all this memory:
ClusterSet::~ClusterSet() {
  ClusterSet::iterator clust_it;
  for (clust_it = clusters.begin(); clust_it != clusters.end(); ++clust_it) {
      std::cout << "Deleting members for " << clust_it->first << std::endl;
      delete clust_it->second;
  }
}

When my destructor is called, it seems to deallocate all the inner maps correctly (it prints out "Deleting members for..." for each one).  However, once that's done I get a runtime error that says "failed to "munmap" 1068 bytes: Invalid argument".  What's causing this?
I have briefly looked at the "rule of three" but I don't understand why I would need a copy constructor or an assignment operator, or how that might solve my problem.  I would never need to use either directly.

A:

There's no good reason (and plenty of disadvantages) for dynamically allocating the inner maps. Change the outer map type to
std::map<std::string, std::map<std::string, float> >

and then you won't need to implement your own destructor and copy/move semantics at all (unless you want to change those you get from the map, perhaps to prevent copying your class).
If, in other circumstances, you really do need to store pointers to objects and tie their lifetime to their presence in the map, store smart pointers:
std::map<std::string, std::unique_ptr<something> >

If you really want to manage their lifetimes by hand for some reason, then you will need to follow the Rule of Three and give your class valid copy semantics (either preventing copying by deleting the copy constructor/assignment operator, or implementing whatever semantics you want). Even if you don't think you're copying objects, it's very easy to write code that does.

