Boost logo

Boost Users :

From: David Greene (greened_at_[hidden])
Date: 2006-02-15 11:38:31


David Greene wrote:
> David Greene wrote:
>
>>I'm starting to use boost::program_options and am not having much
>>luck:
>
>
> Some more information:
>
> I'm using Boost 1.33.1 with g++ 4.0.2 on x86 Linux. When I switch
> to g++ 3.3.3 running the test with no options works. Running
> with --help works. Running with any --debug options causes a
> segfault.

After some investigation I discovered that the first "free(): Invalid
pointer" message appears during execution cmdline::run. At line 244
of cmdline.cpp, there's a break statement that triggers the destruction
of local vector<option> next. Valgrind reports the bad free and I've
attached the report below. Hopefully that will be helpful.

I'm willing to patch my sources in the short term but I need some
help determining the problem. I'm not familiar with the internals
of program_options.

Thanks.

                               -Dave

-----------------
Valgrind report

==31224== Invalid free() / delete / delete[]
==31224== at 0x1B8FF622: operator delete(void*) (vg_replace_malloc.c:246)
==31224== by 0x80509E8:
__gnu_cxx::new_allocator<boost::program_options::basic_option<char>
>::deallocate(boost::program_options::basic_option<char>*, unsigned)
(new_allocator.h:94)
==31224== by 0x8050A12:
std::_Vector_base<boost::program_options::basic_option<char>,
std::allocator<boost::program_options::basic_option<char> >
>::_M_deallocate(boost::program_options::basic_option<char>*, unsigned)
(stl_vector.h:123)
==31224== by 0x8050A51:
std::_Vector_base<boost::program_options::basic_option<char>,
std::allocator<boost::program_options::basic_option<char> >
>::~_Vector_base() (stl_vector.h:109)
==31224== by 0x8052D4B:
std::vector<boost::program_options::basic_option<char>,
std::allocator<boost::program_options::basic_option<char> > >::~vector()
(stl_vector.h:273)
==31224== by 0x1B93834A:
boost::program_options::detail::cmdline::run() (cmdline.cpp:244)
==31224== by 0x80541C3:
boost::program_options::basic_command_line_parser<char>::run()
(parsers.hpp:102)
==31224== by 0x80542BE:
boost::program_options::basic_parsed_options<char>
boost::program_options::parse_command_line<char>(int, char**,
boost::program_options::options_description const&, int,
boost::function1<std::pair<std::string, std::string>, std::string
const&, std::allocator<boost::function_base> >) (parsers.hpp:119)
==31224== by 0x804EEBC: test::process_options(int, char**)
(options.cc:69)
==31224== by 0x804F177: main (options.cc:87)
==31224== Address 0x1BCA7200 is 1096 bytes inside a block of size 1152
alloc'd
==31224== at 0x1B8FE899: malloc (vg_replace_malloc.c:149)
==31224== by 0x1BC7F3BD: operator new(unsigned) (new_op.cc:48)
==31224== by 0x1BC6BC10: std::__default_alloc_template<true,
0>::_S_chunk_alloc(unsigned, int&) (stl_alloc.h:109)
==31224== by 0x1BC6BB1C: std::__default_alloc_template<true,
0>::_S_refill(unsigned) (stl_alloc.h:561)
==31224== by 0x1BC6B60B: std::__default_alloc_template<true,
0>::allocate(unsigned) (stl_alloc.h:365)
==31224== by 0x1BC716E7: std::string::_Rep::_S_create(unsigned,
std::allocator<char> const&) (stl_alloc.h:685)
==31224== by 0x1BC724F4: char* std::string::_S_construct<char
const*>(char const*, char const*, std::allocator<char> const&,
std::forward_iterator_tag) (basic_string.tcc:150)
==31224== by 0x1BC6E7B3: std::string::string(char const*,
std::allocator<char> const&) (basic_string.h:732)
==31224== by 0x1B942DB5:
boost::program_options::option_description::set_name(char const*)
(options_description.cpp:115)
==31224== by 0x1B942873:
boost::program_options::option_description::option_description(char
const*, boost::program_options::value_semantic const*, char const*)
(options_description.cpp:49)
==31224== by 0x1B943295:
boost::program_options::options_description_easy_init::operator()(char
const*, char const*) (options_description.cpp:172)
==31224== by 0x804EBB1: test::process_options(int, char**)
(options.cc:46)
==31224==


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