Boost logo

Boost Users :

Subject: [Boost-users] Program options (1.43.0) problem on Mac OS 10.6: pointer being freed not allocated
From: Robert McLay (mclay_at_[hidden])
Date: 2010-06-02 00:20:30


I'm using boost 1.43.0. I have enclose a program which uses
boost::program_options on a Mac OS 10.6 and when I run it, I get
errors. I have compiled boost with g++ version 4.4.1 and version 4.5.0
and I get the same errors. I have tried the version of boost (1.42.0)
that comes from macports as well as downloaded version that I have build.

clo(87082) malloc: *** error for object 0xa0136db0: pointer being freed
was not allocated.

The program is given below. I have run the same program with boost
1.43.0 under linux and I don't get any errors. It is also completely
clean of any errors when run through valgrind. The program is an
example showing problem I'm having. It has been extracted from a larger
program. Am I correctly using the library
or is there a problem with boost (and only on a Mac?)

Thanks for any help.
-----------------------------------------------------------------------------------------------------------------------

#include<iostream>
#include<string>
#include<boost/program_options.hpp>
class CmdLineOptions
{
    public:
     CmdLineOptions(int argc, char* argv[]);

     bool is_good() {return m_isGood;}

    public:
     bool negative;
     int clustSize;
     float rebuildRatio;
     std::string input_file;

    private:
     bool m_isGood;
};

namespace po = boost::program_options;
CmdLineOptions::CmdLineOptions(int argc, char* argv[])
     : m_isGood(true)
{
     po::options_description visible("Options");
     visible.add_options()
       ("version,v", "print version string")
       ("help,h", "produce help message")
       ("question,?", "produce help message")
       ("clust_size,s", po::value<int>()->default_value(30),
                           "cluster size")
       ("rebuild_ratio,r", po::value<float>()->default_value(0.5),
                           "Rebuild ratio")
       ("negative,n", "Allow negative distances")
       ;

     // Hidden options, will be allowed both on command line
     po::options_description hidden("Hidden options");
     hidden.add_options()
       ("input-file", po::value<std::string>(), "input file")
       ;

     po::options_description cmdline_options;
     cmdline_options.add(visible).add(hidden);

     po::positional_options_description p;
     p.add("input-file", -1);

     po::variables_map vm;
     store(po::command_line_parser(argc, argv).
           options(cmdline_options).positional(p).run(), vm);

     if (vm.count("input-file") == 0 || vm.count("help") ||
vm.count("question"))
       {
         std::cerr<< "\nUsage:\n"
<< " "<< argv[0]<< " [options] input_file\n\n"
<< visible<< std::endl;
         m_isGood = false;
         return;
       }

     clustSize = vm["clust_size"].as<int>();
     input_file = vm["input-file"].as<std::string>();
     rebuildRatio = vm["rebuild_ratio"].as<float>();
     negative = vm.count("negative")> 0;
}

int main(int argc, char * argv[])
{

     // Parse Command line options
     CmdLineOptions cmd(argc, argv);
     if (! cmd.is_good())
       return 1;

     std::cout<< "clustSize: "<< cmd.clustSize<< " rebuild factor: "<<
   cmd.rebuildRatio<< "\n";

}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net