Strange application crash - c++

I have this C++ application running on a Ubuntu Lucid 10.04.3 LTS which is crashed and the reason really escapes me.
The method which exhibits failure is this one:
void
IoLogikCommunicator::processPacket(char const* data, WORD wSize)
{
std::string message(data, wSize);
std::stringstream ss(message);
std::string token;
std::vector<std::string> tokens;
while (std::getline(ss, token, '#')) // <- crash
tokens.push_back(token);
if (tokens[0] == "SENSORS")
processSensorsPacket(tokens);
else if (tokens[0] == "SELECTOR")
processSelectorPacket(tokens);
}
According to the core dump, data content is valid and it is:
p data
$1 = 0xb7520214 "SENSORS#192.168.107.62#DI:00#ON#DI:01#ON#DI:02#ON#DI:03#OFF#DI:04#OFF#DI:05#OFF"
p wSize
$2 = 79
The content of tokens, at crash time, is ["SENSORS"], so the first element was parsed correctly.
What happens then is:
Program terminated with signal 6, Aborted.
#0 0x009de422 in __kernel_vsyscall ()
(gdb) bt
#0 0x009de422 in __kernel_vsyscall ()
#1 0x0766a651 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0x0766da82 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0x076a149d in ?? () from /lib/tls/i686/cmov/libc.so.6
#4 0x076ab591 in ?? () from /lib/tls/i686/cmov/libc.so.6
#5 0x076ae710 in ?? () from /lib/tls/i686/cmov/libc.so.6
#6 0x076aff9c in malloc () from /lib/tls/i686/cmov/libc.so.6
#7 0x0070dc07 in operator new(unsigned int) () from /usr/lib/libstdc++.so.6
#8 0x006e7d06 in std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) () from /usr/lib/libstdc++.so.6
#9 0x006e9f70 in std::string::_M_mutate(unsigned int, unsigned int, unsigned int) () from /usr/lib/libstdc++.so.6
#10 0x006c4274 in std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char) () from /usr/lib/libstdc++.so.6
given the SIGABRT it seems that an assert() fails inside the malloc invocation, but what could be the reason? Of course, it was impossible for me to reproduce the bug: this method is invoked several times per second and the application crashed after 30 and more days of continuous running.
The very same data, then, is processed by another identical application which is hosted on another machine: that one didn't crash.
Do you have any suggestion/hint/tips/pointer?

Related

How to debug a sycl runtime compilation that fails with segmentation fault

The point of the question
I have a minimal program that segfaults during sycl runtime compilation. For the sake of detail i have precise reproduction details below. However, the point of this question is to understand how to debug this. It took me a long time to make the minimal example. I suspect if i could get the runtimes for dpcpp i could probably have cut this right down. When the runtime compiler fails, it should throw an exception. I want to know what steps i should take to discover why it is instead segfaulting, and if it is a compiler bug or a bug in my code.
Reproduction details below
starting with the code:
#include <CL/sycl/queue.hpp>
#include <CL/sycl/device.hpp>
#include <CL/sycl/context.hpp>
#include <CL/sycl.hpp>
#include <iostream>
namespace
{
auto is_sign_same(sycl::short3 idx1, sycl::short3 idx2)
{
return (idx1 < 0) == (idx2 < 0);
}
} // namespace
int main()
{
sycl::device device = sycl::device{sycl::gpu_selector{}};
std::cout
<< "\n\nRunning occupancy grid profile. The profile will have the following "
"properties:\n\n Device:\t"
<< device.get_info<sycl::info::device::name>() << "\n\n";
sycl::context context{device};
sycl::property_list properties{sycl::property::queue::enable_profiling()};
sycl::queue queue{device, properties};
auto event = queue.submit(
[](sycl::handler& cgh)
{
// 1. This must be captured or it does not crash. If i put this in the
// kernel, then it does not fail.
sycl::id<3> robot_index{0, 0, 0};
sycl::stream out(1024, 256, cgh);
cgh.parallel_for(
sycl::range<3>{4, 4, 4},
[out, robot_index](sycl::id<3> id)
{
sycl::short3 new_signed_idx{short(0)};
// 2. I cannot remove the subtract between the 2 sycl::short3 here.
// It will not fail.
sycl::short3 old_signed_idx =
sycl::short3{
(short)id.get(0), (short)id.get(1), (short)id.get(2)} -
sycl::short3{
(short)robot_index.get(0),
(short)robot_index.get(1),
(short)robot_index.get(2)};
// 3. I cannot replace this function call with the operation that
// the function performs inline here. It does not fail.
auto s_same = is_sign_same(new_signed_idx, old_signed_idx);
out << s_same;
}
);
}
);
return 0;
}
When compiled using:
/opt/intel/oneapi/compiler/2022.1.0/linux/bin/dpcpp -fclang-abi-compat=7 -fsycl --gcc-toolchain=/usr -sycl-std=2020 -fp-model=precise -Wall -Werror -fsycl -O2 -g -DNDEBUG -std=gnu++17 sgfaulting_file.cpp
will fail at runtime. The failure is a segfault. It is caused by something do do with building the kernel. If we run the output in GDB we get the following stack trace when it dies:
(gdb) where
#0 0x00007f49e3683b8c in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#1 0x00007f49e36b440c in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#2 0x00007f49e36b0dda in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#3 0x00007f49e36b430f in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#4 0x00007f49e36bac6a in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#5 0x00007f49e36b0bed in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#6 0x00007f49e36b430f in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#7 0x00007f49e36bac6a in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#8 0x00007f49e36bf027 in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#9 0x00007f49e36bf908 in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#10 0x00007f49e35ab7bc in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#11 0x00007f49e35abfba in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#12 0x00007f49e35ae90d in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#13 0x00007f49e36ec3d4 in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#14 0x00007f49e35b21fb in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#15 0x00007f49e36ced9a in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#16 0x00007f49f487f1bb in ?? () from /usr/lib/x86_64-linux-gnu/intel-opencl/libigdrcl.so
#17 0x00007f49f43ef178 in ?? () from /usr/lib/x86_64-linux-gnu/intel-opencl/libigdrcl.so
#18 0x00007f49f4397b33 in ?? () from /usr/lib/x86_64-linux-gnu/intel-opencl/libigdrcl.so
#19 0x00007f49f9327aa4 in cl::sycl::detail::ProgramManager::build(std::unique_ptr<_pi_program, _pi_result (*)(_pi_program*)>, std::shared_ptr<cl::sycl::detail::context_impl>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _pi_device* const&, std::map<std::pair<cl::sycl::detail::DeviceLibExt, _pi_device*>, _pi_program*, std::less<std::pair<cl::sycl::detail::DeviceLibExt, _pi_device*> >, std::allocator<std::pair<std::pair<cl::sycl::detail::DeviceLibExt, _pi_device*> const, _pi_program*> > >&, unsigned int) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#20 0x00007f49f9321336 in cl::sycl::detail::ProgramManager::getBuiltPIProgram(long, std::shared_ptr<cl::sycl::detail::context_impl> const&, std::shared_ptr<cl::sycl::detail::device_impl> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cl::sycl::detail::program_impl const*, bool) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#21 0x00007f49f932243c in cl::sycl::detail::ProgramManager::getOrCreateKernel(long, std::shared_ptr<cl::sycl::detail::context_impl> const&, std::shared_ptr<cl::sycl::detail::device_impl> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cl::sycl::detail::program_impl const*) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#22 0x00007f49f93630f1 in cl::sycl::detail::enqueueImpKernel(std::shared_ptr<cl::sycl::detail::queue_impl> const&, cl::sycl::detail::NDRDescT&, std::vector<cl::sycl::detail::ArgDesc, std::allocator<cl::sycl::detail::ArgDesc> >&, std::shared_ptr<cl::sycl::detail::kernel_bundle_impl> const&, std::shared_ptr<cl::sycl::detail::kernel_impl> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, long const&, std::vector<_pi_event*, std::allocator<_pi_event*> >&, _pi_event**, std::function<void* (cl::sycl::detail::AccessorImplHost*)> const&) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#23 0x00007f49f9369f3b in cl::sycl::detail::ExecCGCommand::enqueueImp() ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#24 0x00007f49f93566c5 in cl::sycl::detail::Command::enqueue(cl::sycl::detail::EnqueueResultT&, cl::sycl::detail::BlockingT, std::vector<cl::sycl::detail::Command*, std::allocator<cl::sycl::detail::Command*> >&) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#25 0x00007f49f9373b7b in cl::sycl::detail::Scheduler::addCG(std::unique_ptr<cl::sycl::detail::CG, std::default_delete<cl::sycl::detail::CG> >, std::shared_ptr<cl::sycl::detail::queue_impl>) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#26 0x00007f49f93aef30 in cl::sycl::handler::finalize() ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#27 0x00007f49f93dc3ea in cl::sycl::detail::queue_impl::finalizeHandler(cl::sycl::handler&, cl::sycl::detail::CG::CGTYPE const&, cl::sycl::event&) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#28 0x00007f49f93dc13b in cl::sycl::detail::queue_impl::submit_impl(std::function<void (cl::sycl::handler&)> const&, std::shared_ptr<cl::sycl::detail::queue_impl> const&, std::shared_ptr<cl::sycl::detail::queue_impl> const&, std::shared_ptr<cl::sycl::detail::queue_impl> const&, cl::sycl::detail::code_location const&, std::function<void (bool, bool, cl::sycl::event&)> const*) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#29 0x00007f49f93db744 in cl::sycl::detail::queue_impl::submit(std::function<void (cl::sycl::handler&)> const&, std::shared_ptr<cl::sycl::detail::queue_impl> const&, cl::sycl::detail::code_location const&, std:--Type <RET> for more, q to quit, c to continue without paging--
:function<void (bool, bool, cl::sycl::event&)> const*) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#30 0x00007f49f93db715 in cl::sycl::queue::submit_impl(std::function<void (cl::sycl::handler&)>, cl::sycl::detail::code_location const&) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#31 0x00000000004026d8 in cl::sycl::queue::submit<main::{lambda(cl::sycl::handler&)#1}>(main::{lambda(cl::sycl::handler&)#1}, cl::sycl::detail::code_location const&) (this=0x7ffc5da1b200, CodeLoc=..., CGF=...)
at /opt/intel/oneapi/compiler/2022.1.0/linux/bin-llvm/../include/sycl/CL/sycl/queue.hpp:275
#32 main () at occupancy_grid_point_cloud_creation.cpp:31
The important part being stack position #19:
cl::sycl::detail::ProgramManager::build
The runtime compilation is occurring on the device (from sycl-ls):
[opencl:gpu:2] Intel(R) OpenCL HD Graphics, Intel(R) UHD Graphics [0x9bc4] 3.0 [22.28.23726.1]
if we run the same program but use a host or cpu selector, we do not fail to build and can run successfully. It also seems that if we change minimal details about the program, it also no longer segfaults. These small changes are detailed in the comments in the program.

opencv c++ corrupted double-linked list

I'm trying to get the fps from multiple cameras. This is the main:
int main(int argc, char* argv[])
{
//Load all cameras IP
map<string, string> camerasIp; //camera ID and Streaming URL
LoadConfig(&camerasIp);
//Get FPS of all cameras
map<string,string>::iterator it_cam;
while(true)
{
for(it_cam = camerasIp.begin(); it_cam != camerasIp.end(); ++it_cam)
{
GetCamFps(it_cam->second);
}
cout << "" << endl;
}
//Send FPS to server
...
return 0;
}
This is the GetCamFps method:
void GetCamFps(string url)
{
cout << "VideoCapture" << endl;
VideoCapture video(url);
cout << "Get frames" << endl;
double fps = video.get(CAP_PROP_FPS);
cout <<"Frames: " << fps << endl;
video.release();
}
And this is the exit:
VideoCapture
Get frames
Frames: 30
VideoCapture
corrupted double-linked list
Aborted (core dumped)
I tried adding a sleep to let some time between opening one url and another but didn't works. I checked the map and it's correct.
When I comment the two firsts cout in the method it works but after a while it fail again.
Output of gdb with backtrace:
Thread 1 "Fps_Monitoring" received signal SIGABRT, Aborted.
__GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) backtrace
#0 __GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x00007ffff51cc801 in __GI_abort () at abort.c:79
#2 0x00007ffff5215897 in __libc_message (action=action#entry=do_abort, fmt=fmt#entry=0x7ffff5342b9a "%s\n") at ../sysdeps/posix/libc_fatal.c:181
#3 0x00007ffff521c90a in malloc_printerr (str=str#entry=0x7ffff5340cba "corrupted double-linked list") at malloc.c:5350
#4 0x00007ffff521cac4 in malloc_consolidate (av=av#entry=0x7ffff5577c40 <main_arena>) at malloc.c:4456
#5 0x00007ffff52207d8 in _int_malloc (av=av#entry=0x7ffff5577c40 <main_arena>, bytes=bytes#entry=1600) at malloc.c:3703
#6 0x00007ffff52214eb in _int_memalign (av=0x7ffff5577c40 <main_arena>, alignment=64, bytes=<optimized out>) at malloc.c:4694
#7 0x00007ffff5226fba in _mid_memalign (address=<optimized out>, bytes=1496, alignment=<optimized out>) at malloc.c:3314
#8 __posix_memalign (memptr=0x7fffffffdad0, alignment=<optimized out>, size=1496) at malloc.c:5369
#9 0x00007ffff028e7e3 in av_malloc () from /usr/local/lib/libavutil.so.56
#10 0x00007ffff06b253b in avformat_alloc_context () from /usr/local/lib/libavformat.so.58
#11 0x00007ffff5f8b9a3 in CvCapture_FFMPEG::open(char const*) () from /usr/local/lib/libopencv_videoio.so.4.2
#12 0x00007ffff5f8e9ff in cv::cvCreateFileCapture_FFMPEG_proxy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
from /usr/local/lib/libopencv_videoio.so.4.2
#13 0x00007ffff5f71566 in cv::StaticBackend::createCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const ()
from /usr/local/lib/libopencv_videoio.so.4.2
#14 0x00007ffff5f4cc17 in cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ()
from /usr/local/lib/libopencv_videoio.so.4.2
#15 0x00007ffff5f4f595 in cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ()
from /usr/local/lib/libopencv_videoio.so.4.2
#16 0x000055555555f9b3 in GetCamFps(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) ()
#17 0x000055555555d5df in main ()
Any idea why the second videocapture doesn't work?
Thanks.

ROOT: Segmentation violation

I am running Cern ROOT 6.22/00 on Ubuntu 18.04. I am running a very simple code that reads data and plots a graph.
// filename.C Example of graph with SetPoint
{
g = new TGraph();
for(i=0; i<10; i++) {
g->SetPoint(i, i, i*i - 4*i + 7);
}
g->SetMarkerStyle(22);
g->Draw("ALP");
}
When I go ahead and execute the code with .x filename.C, the code works as intended. However, when I run the same command again, I get the segmentation error:
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f7c2e7166e7 in waitpid () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007f7c2e681107 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007f7c2f2b8ed3 in TUnixSystem::StackTrace() () from /home/nick/root/lib/libCore.so.6.22
#3 0x00007f7c2f2bb9c5 in TUnixSystem::DispatchSignals(ESignals) () from /home/nick/root/lib/libCore.so.6.22
#4 <signal handler called>
#5 0x00007f7c29f24393 in (anonymous namespace)::ScalarExprEmitter::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation, bool) () from /home/nick/root/lib/libCling.so
#6 0x00007f7c29f25e84 in clang::CodeGen::CodeGenFunction::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation) () from /home/nick/root/lib/libCling.so
#7 0x00007f7c29eed6e0 in clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) () from /home/nick/root/lib/libCling.so
#8 0x00007f7c29d70dc3 in clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) () from /home/nick/root/lib/libCling.so
#9 0x00007f7c29d6f305 in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) () from /home/nick/root/lib/libCling.so
#10 0x00007f7c29d6f42f in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /home/nick/root/lib/libCling.so
#11 0x00007f7c29daab12 in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) () from /home/nick/root/lib/libCling.so
#12 0x00007f7c29dc8098 in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/nick/root/lib/libCling.so
#13 0x00007f7c29dea828 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/nick/root/lib/libCling.so
#14 0x00007f7c29debb05 in clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) () from /home/nick/root/lib/libCling.so
#15 0x00007f7c29dec46f in clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) () from /home/nick/root/lib/libCling.so
#16 0x00007f7c29d2edfd in clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#17 0x00007f7c2a07aba0 in clang::MultiplexConsumer::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#18 0x00007f7c29ca5aea in cling::DeclCollector::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#19 0x00007f7c29c72bec in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /home/nick/root/lib/libCling.so
#20 0x00007f7c29c7540c in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /home/nick/root/lib/libCling.so
#21 0x00007f7c29bf36ad in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/nick/root/lib/libCling.so
#22 0x00007f7c29bf3aaa in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /home/nick/root/lib/libCling.so
#23 0x00007f7c29cb50df in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, unsigned long, bool) () from /home/nick/root/lib/libCling.so
#24 0x00007f7c29b6e004 in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/nick/root/lib/libCling.so
#25 0x00007f7c29b6eaa2 in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /home/nick/root/lib/libCling.so
#26 0x00007f7c2f15cba8 in TApplication::ExecuteFile(char const*, int*, bool) () from /home/nick/root/lib/libCore.so.6.22
#27 0x00007f7c2f15c3d0 in TApplication::ProcessLine(char const*, bool, int*) () from /home/nick/root/lib/libCore.so.6.22
#28 0x00007f7c2f6d9002 in TRint::ProcessLineNr(char const*, char const*, int*) () from /home/nick/root/lib/libRint.so.6.22
#29 0x00007f7c2f6d93f4 in TRint::HandleTermInput() () from /home/nick/root/lib/libRint.so.6.22
#30 0x00007f7c2f2bacb0 in TUnixSystem::CheckDescriptors() () from /home/nick/root/lib/libCore.so.6.22
#31 0x00007f7c2f2bc668 in TUnixSystem::DispatchOneEvent(bool) () from /home/nick/root/lib/libCore.so.6.22
#32 0x00007f7c2f1c7751 in TSystem::Run() () from /home/nick/root/lib/libCore.so.6.22
#33 0x00007f7c2f159e7f in TApplication::Run(bool) () from /home/nick/root/lib/libCore.so.6.22
#34 0x00007f7c2f6da9f1 in TRint::Run(bool) () from /home/nick/root/lib/libRint.so.6.22
#35 0x000055f5d5017a3c in main ()
===========================================================
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5 0x00007f7c29f24393 in (anonymous namespace)::ScalarExprEmitter::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation, bool) () from /home/nick/root/lib/libCling.so
#6 0x00007f7c29f25e84 in clang::CodeGen::CodeGenFunction::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation) () from /home/nick/root/lib/libCling.so
#7 0x00007f7c29eed6e0 in clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) () from /home/nick/root/lib/libCling.so
#8 0x00007f7c29d70dc3 in clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) () from /home/nick/root/lib/libCling.so
#9 0x00007f7c29d6f305 in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) () from /home/nick/root/lib/libCling.so
#10 0x00007f7c29d6f42f in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /home/nick/root/lib/libCling.so
#11 0x00007f7c29daab12 in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) () from /home/nick/root/lib/libCling.so
#12 0x00007f7c29dc8098 in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/nick/root/lib/libCling.so
#13 0x00007f7c29dea828 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/nick/root/lib/libCling.so
#14 0x00007f7c29debb05 in clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) () from /home/nick/root/lib/libCling.so
#15 0x00007f7c29dec46f in clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) () from /home/nick/root/lib/libCling.so
#16 0x00007f7c29d2edfd in clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#17 0x00007f7c2a07aba0 in clang::MultiplexConsumer::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#18 0x00007f7c29ca5aea in cling::DeclCollector::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#19 0x00007f7c29c72bec in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /home/nick/root/lib/libCling.so
#20 0x00007f7c29c7540c in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /home/nick/root/lib/libCling.so
#21 0x00007f7c29bf36ad in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/nick/root/lib/libCling.so
#22 0x00007f7c29bf3aaa in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /home/nick/root/lib/libCling.so
#23 0x00007f7c29cb50df in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, unsigned long, bool) () from /home/nick/root/lib/libCling.so
===========================================================
I am sure it has nothing to do with my code itself, but ideas to resolve this?
I tried your code on ROOT 6.20/06 and it indeed crashed with the same segmentation errors you posted, but I am able to run your code simply by declaring the types of variables g and i:
{
TGraph* g = new TGraph();
for(int i=0; i<10; i++) {
g->SetPoint(i, i, i*i - 4*i + 7);
}
g->SetMarkerStyle(22);
g->Draw("ALP");
}
TGraph::SetPoint method can itself handle the memory allocation issue, so the code has no problem in principle, just need to be careful when declaring variables in C/C++.

SIGSEGV on Boost UDP socket close - tcache_get at malloc.c

I have no idea where this problem might come from:
(Debugging with GDB):
terminate called after throwing an instance of '[Thread 0x7ffff5e68700 (LWP 24945) exited]
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
Thread 1 "random_walkerta" received signal SIGSEGV, Segmentation fault.
tcache_get (tc_idx=1) at malloc.c:2943
StackTrace:
#0 tcache_get (tc_idx=1) at malloc.c:2943
#1 __GI___libc_malloc (bytes=31) at malloc.c:3050
#2 0x00007ffff6ec154c in operator new(unsigned long) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff6f56dbf in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff6f584bb in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00005555555bee66 in boost::system::system_error::what (
this=0x5555558a1bf0) at /usr/include/boost/system/system_error.hpp:70
#6 0x00007ffff6eba8ba in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00007ffff6ec0d3a in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#8 0x00007ffff6ebfd59 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9 0x00007ffff6ec0708 in __gxx_personality_v0 ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007ffff6888763 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#11 0x00007ffff688907d in _Unwind_Resume ()
from /lib/x86_64-linux-gnu/libgcc_s.so.1
#12 0x00005555555cb8d6 in boost::asio::detail::do_throw_error (err=...,
location=0x555555610dba "close")
at /usr/include/boost/asio/detail/impl/throw_error.ipp:37
---Type <return> to continue, or q <return> to quit---
#13 0x00005555555cb741 in boost::asio::detail::throw_error (err=...,
location=0x555555610dba "close")
at /usr/include/boost/asio/detail/throw_error.hpp:42
#14 0x00005555555de022 in boost::asio::basic_socket<boost::asio::ip::udp, boost::asio::datagram_socket_service<boost::asio::ip::udp> >::close (
this=0x555555887ea0) at /usr/include/boost/asio/basic_socket.hpp:356
#15 0x00005555555d7ebe in Vast::net_overhearing_handler::handle_close (
this=0x555555889490) at net_overhearing_handler.cpp:160
#16 0x00005555555d7e4c in Vast::net_overhearing_handler::close (
this=0x555555889490) at net_overhearing_handler.cpp:141
#17 0x00005555555c9b85 in Vast::net_overhearing::stop (this=0x5555558870e0)
at net_overhearing.cpp:88
#18 0x00005555555ba77f in Vast::VASTnet::~VASTnet (this=0x55555587f180,
__in_chrg=<optimized out>) at VASTnet.cpp:63
#19 0x000055555556ca7a in Vast::destroyNet (net=0x55555587f180)
at VASTVerse.cpp:93
#20 0x000055555556d036 in Vast::VASTVerse::~VASTVerse (this=0x55555587e4c0,
__in_chrg=<optimized out>) at VASTVerse.cpp:196
#21 0x000055555556bce4 in main (argc=1, argv=0x7fffffffe598)
at random_walkertalker.cpp:266
The setup is a follows:
I have a Boost UDP socket running on seperate thread io_service, listening for packets. Everything works according to expectation until I try to shutdown the program, UDP socket and io_service. I am guessing I am not correctly shutting something down.
Here is the code for shutting down the UDP and io_services:
if (_io_service != NULL) {
_io_service->reset();
_udp->close(); //This line is giving the error (160)
_io_service->stop();
_iosthread->join();
}
Starting up, I do the following:
_udp = new ip::udp::socket(*_io_service);
_udp->open(ip::udp::v4());
_udp->async_receive_from(
boost::asio::buffer(_buf, VAST_BUFSIZ), _remote_endpoint_,
boost::bind(&net_overhearing_handler::handle_input, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
_iosthread = new boost::thread(boost::bind(&boost::asio::io_service::run, io_service));
Remove this line
_io_service->reset();
because as per the reference io_service::reset
This function must not be called while there are any unfinished calls
to the run(), run_one(), poll() or poll_one() functions.
It seems run method works in thread when you call restart.
You don't need to call this method to stop io_service::run method. All pending operations in run will be cancelled by calling _io_service->stop(); then run stops and your thread also terminates.

terminate called after throwing an instance of 'std::logic_error'

I am using C++ for a program retrieving informations about files. Among them, I want to find out the MIME type of a given file.
To do so I use libmagic as follow:
#include <iostream>
#include <string>
#include <magic.h>
void foo (std::string path)
{
magic_t magic;
magic = magic_open (MAGIC_MIME_TYPE);
magic_load(magic, NULL);
magic_compile(magic, NULL);
std::string filetype (magic_file(magic, path.c_str()));
magic_close(magic);
std::cout << filetype << std::endl;
}
int main(int argc, char *argv[])
{
std::string str = "test.cxx";
foo (str);
return 0;
}
Trying on a computer running on Debian Jessie with gcc 4.9.2 and glibc 2.19, it works just fine.
However, on another computer on arch linux with gcc 5.1.0 and glibc 2.21, I have the following at runtime:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
gdb gives me additional information:
Program received signal SIGABRT, Aborted.
0x00007ffff6fb1528 in raise () from /usr/lib/libc.so.6
#0 0x00007ffff6fb1528 in raise () from /usr/lib/libc.so.6
#1 0x00007ffff6fb293a in abort () from /usr/lib/libc.so.6
#2 0x00007ffff78c9b3d in __gnu_cxx::__verbose_terminate_handler ()
at /build/gcc/src/gcc-5-20150519/libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00007ffff78c7996 in __cxxabiv1::__terminate (handler=<optimized out>)
at /build/gcc/src/gcc-5-20150519/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4 0x00007ffff78c79e1 in std::terminate ()
at /build/gcc/src/gcc-5-20150519/libstdc++-v3/libsupc++/eh_terminate.cc:57
#5 0x00007ffff78c7bf8 in __cxxabiv1::__cxa_throw (obj=0x613fb0,
tinfo=0x7ffff7baea78 <typeinfo for std::logic_error>,
dest=0x7ffff78dd040 <std::logic_error::~logic_error()>)
at /build/gcc/src/gcc-5-20150519/libstdc++-v3/libsupc++/eh_throw.cc:87
#6 0x00007ffff78f08bf in std::__throw_logic_error (
__s=__s#entry=0x7ffff7976100 "basic_string::_S_construct null not valid")
at /build/gcc/src/gcc-5-20150519/libstdc++-v3/src/c++11/functexcept.cc:74
#7 0x00007ffff790acef in std::string::_S_construct<char const*> (__beg=<optimized out>,
__end=<optimized out>, __a=...)
at /build/gcc/src/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:577
#8 0x00007ffff790b0e6 in _S_construct_aux<char const*> (__a=..., __end=<optimized out>,
__beg=0x0)
at /build/gcc/src/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/basic_string.h:4136
#9 _S_construct<char const*> (__a=..., __end=<optimized out>, __beg=0x0)
at /build/gcc/src/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/basic_string---Type <return> to continue, or q <return> to quit---
.h:4157
#10 std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (
this=0x7fffffffe980, __s=0x0, __a=...)
at /build/gcc/src/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:659
#11 0x0000000000400df3 in foo (path="test.cxx") at test.cxx:11
#12 0x0000000000400ece in main (argc=1, argv=0x7fffffffeae8) at test.cxx:21
So I'm not quite sure if I can solve my problem, or is there a possible bug coming from glibc or libmagic?