[program_options] Multiple segfaults

I'm starting to use boost::program_options and am not having much luck:
-home-> ./options_test Got debug value default Got option default Segmentation fault (core dumped)
-home-> ./options_test --help free(): invalid pointer 0x8fb06f8! free(): invalid pointer 0x8fafcd0! Got debug value default Got option default Segmentation fault (core dumped)
-home-> ./options_test --help --debug io free(): invalid pointer 0x8a83ec0! free(): invalid pointer 0x8a83ed0! free(): invalid pointer 0x8a83ec8! free(): invalid pointer 0x8a84a38! Segmentation fault (core dumped)
At first I thought it might be a problem with the -mt version as
my larger application is threaded. But I compiled the testcase
attached below as a single-threaded application and it still fails
in the same ways.
I'm not sure if my use of vector<string> is correct. The documentation
is confusing on this point. In
http://boost.sourceforge.net/doc/html/program_options/overview.html
one example with the "email" option uses multitoken with "string"
and another uses "combining" with "vector<string>." Is it not
possible to have a combining and multitoken option value? What's
the correct value type to use if I want the multiple tokens for
the "debug" option to appear as separate items in a vector (or
other sequence)? Or do I have to stuff them in a single string
and manually parse them out later?
-Dave
------------------------
#include

Hi, I am new to Boost library. I wonder if the Boost functional library is a sub-set of the Boost bind library? http://www.boost.org/libs/functional/ http://www.boost.org/libs/bind If now, what functionality that functional library provides that bind library does not? Thank you. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

yinglcs2@yahoo.com wrote:
Hi,
I am new to Boost library. I wonder if the Boost functional library is a sub-set of the Boost bind library?
http://www.boost.org/libs/functional/
http://www.boost.org/libs/bind
If now, what functionality that functional library provides that bind library does not?
The functional library is a better way of using a number of adapters in the current C++ standard library for creating function objects. Bind is much more advanced, and much easier, than using the C++ standard library adapters, and is a much better paradigm for using function objects. The only adapters in the functional library you still might want to use with bind are the Negators, whereas bind very adequately replaces the rest of functional, and its original C++ standard equivalents. Bind also offers more advanced functionality, mostly having to do with argument replacement and manipulation when calling the bound (member) function. You might also want to look at Boost lambda, which is similar to the functionality which bind offers, using a different more in-line syntax, which is not intended to save the function object for later use, when calling a bound (member) function. Boost lambda needs a highly C++ compliant compiler, and a number of older or lesser C++ compliant compilers do not work with Boost lambda. A Boost bind object, which is a C++ function object, can be saved as a Boost function, for use as a callback, or used in Boost signals as a signal handler.

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. Any ideas on where to start? -Dave

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 ::deallocate(boost::program_options::basic_option<char>*, unsigned)
(new_allocator.h:94)
==31224== by 0x8050A12:
std::_Vector_base

David Greene wrote:
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.
This _may_ be due to a standard library mismatch problem. I'm looking at that right now so don't work too hard on this yet. :) -Dave

David Greene wrote:
David Greene wrote:
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.
This _may_ be due to a standard library mismatch problem. I'm looking at that right now so don't work too hard on this yet. :)
Indeed, this was the problem. Apologies for the noise. -Dave
participants (3)
-
David Greene
-
Edward Diener
-
yinglcs2@yahoo.com