Folks,
Thanks for making octplot!
On debian sarge, but with a home-built octave 2.71, I built octplot with gcc 4.0.4. As soon as I try to run line_demo, it segfaults.
If I run under gdb and do a bt, I get:
Program received signal SIGSEGV, Segmentation fault.
0x411722d6 in free () from /lib/libc.so.6
#0 0x411722d6 in free () from /lib/libc.so.6
#1 0x415244e1 in operator delete () from /usr/lib/libstdc++.so.6
#2 0x415001ed in std::string::_Rep::_M_destroy () from /usr/lib/libstdc++.so.6
#3 0x41502d58 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string () from /usr/lib/libstdc++.so.6
#4 0x414326e2 in Foctplot_command (args=@0x8bd1188, nargout=1)
at octplot_command.cc:170
#5 0x403bd7bc in octave_builtin::do_multi_index_op (this=0x8968590,
nargout=0, args=@0x8bd1188) at oct-obj.h:79
#6 0x403bcd15 in octave_builtin::subsref (this=0x8968590, type=@0x8c57d80,
idx=@0xbfff80b0, nargout=1) at /usr/include/c++/3.3/bits/stl_list.h:678
#7 0x4039c137 in octave_value::subsref (this=0xbfff80d0, type=@0x8c57d80,
idx=@0xbfff80b0, nargout=0) at ov.cc:837
#8 0x404a7f94 in tree_index_expression::rvalue (this=0x8c57d60, nargout=1)
at oct-obj.h:79
#9 0x404a902d in tree_index_expression::rvalue (this=0x8c57d60)
at pt-idx.cc:363
#10 0x4048a40e in tree_simple_assignment::rvalue (this=0x8d203f8)
at oct-obj.h:51
#11 0x40489941 in tree_simple_assignment::rvalue (this=0x8d203f8, nargout=0)
at oct-obj.h:51
#12 0x404d4d62 in tree_statement::eval (this=0x8cbd1a0, silent=false,
nargout=0, in_function_body=false) at oct-obj.h:79
I played with the code a little, and it seems that just creating a temporary string_value to get the size of the input argument results in the segfault when the temporary gets deleted as it goes out of scope.
I tried setting GLIBCXX_FORCE_NEW=1 and rebuilding, but no change. Any other ideas?
Thanks in advance,
Paul Probert
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So it faults before the next cout. Since the fault is in delete, I leapt to the conclusion that it is faulting when trying to deleted the temporary string_value that got created to call its size method.
Paul Probert
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks, Shai. I tried what you suggested. Even creating the std::string tmp, if I take the .size() of it I get the segfault.
Something is very wrong with my setup here. I must have somehow gotten bad C or C++ libraries installed, probably sometime since I built octave. I have to go learn how to diagnose and fix this. I'm sure its nothing wrong with octplot.
Paul Probert
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Folks,
Thanks for making octplot!
On debian sarge, but with a home-built octave 2.71, I built octplot with gcc 4.0.4. As soon as I try to run line_demo, it segfaults.
If I run under gdb and do a bt, I get:
Program received signal SIGSEGV, Segmentation fault.
0x411722d6 in free () from /lib/libc.so.6
#0 0x411722d6 in free () from /lib/libc.so.6
#1 0x415244e1 in operator delete () from /usr/lib/libstdc++.so.6
#2 0x415001ed in std::string::_Rep::_M_destroy () from /usr/lib/libstdc++.so.6
#3 0x41502d58 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string () from /usr/lib/libstdc++.so.6
#4 0x414326e2 in Foctplot_command (args=@0x8bd1188, nargout=1)
at octplot_command.cc:170
#5 0x403bd7bc in octave_builtin::do_multi_index_op (this=0x8968590,
nargout=0, args=@0x8bd1188) at oct-obj.h:79
#6 0x403bcd15 in octave_builtin::subsref (this=0x8968590, type=@0x8c57d80,
idx=@0xbfff80b0, nargout=1) at /usr/include/c++/3.3/bits/stl_list.h:678
#7 0x4039c137 in octave_value::subsref (this=0xbfff80d0, type=@0x8c57d80,
idx=@0xbfff80b0, nargout=0) at ov.cc:837
#8 0x404a7f94 in tree_index_expression::rvalue (this=0x8c57d60, nargout=1)
at oct-obj.h:79
#9 0x404a902d in tree_index_expression::rvalue (this=0x8c57d60)
at pt-idx.cc:363
#10 0x4048a40e in tree_simple_assignment::rvalue (this=0x8d203f8)
at oct-obj.h:51
#11 0x40489941 in tree_simple_assignment::rvalue (this=0x8d203f8, nargout=0)
at oct-obj.h:51
#12 0x404d4d62 in tree_statement::eval (this=0x8cbd1a0, silent=false,
nargout=0, in_function_body=false) at oct-obj.h:79
I played with the code a little, and it seems that just creating a temporary string_value to get the size of the input argument results in the segfault when the temporary gets deleted as it goes out of scope.
I tried setting GLIBCXX_FORCE_NEW=1 and rebuilding, but no change. Any other ideas?
Thanks in advance,
Paul Probert
Paul,
Can you explain your conclusion about the temporary string_value?
I see the error is in octplot_command.cc:170, and I don't see any string there.
Shai
p.s. GLIBCXX_FORCE_NEW=1 is a runtime parameter -- you don't have to recompile fot it to have effect.
Thanks for your reply.
Line 170 in my editor is:
char* str=new char[args(cur_arg+1).string_value().size()+1];
If I put a few lines ahead of it like this:
std::cout << "testing..."<<std::endl;
std::cout << "size="<<args(cur_arg+1).string_value().size()<<std::endl;
std::cout << "end testing"<<std::endl;
char* str=new char[args(cur_arg+1).string_value().size()+1];
Then I run it in octave:
octave:1> toggle_octplot
octave:2> line_demo
testing...
size=13
panic: Segmentation fault -- stopping myself...
So it faults before the next cout. Since the fault is in delete, I leapt to the conclusion that it is faulting when trying to deleted the temporary string_value that got created to call its size method.
Paul Probert
Thanks,
does changing it into a non temporary help? something along the lines of:
std::string tmp = args(cur_arg+1).string_value();
char *str=new char[tmp.size()+1];
strcpy(str,tmp.c_str());
Shai
Thanks, Shai. I tried what you suggested. Even creating the std::string tmp, if I take the .size() of it I get the segfault.
Something is very wrong with my setup here. I must have somehow gotten bad C or C++ libraries installed, probably sometime since I built octave. I have to go learn how to diagnose and fix this. I'm sure its nothing wrong with octplot.
Paul Probert