On Fri, Aug 18, 2017 at 4:21 AM,  <ine...@gmail.com> wrote:
>
> I have a C++ application from which I need to call Go functions. I noticed
> that the application crashes
> on exit from the `main` function (with only a "Segmentation fault" message,
> no core dump and neither
> did gdb show anything useful) about once in three runs.

That is a problem.  When you say that gdb doesn't show anything
useful, what do you mean?  Does it at least show where the
segmentation fault is occurring?


> Then I added the
> `-fsanitize=address` flag to
> the build and started to see messages such as these:

These are not problems.  These just  mean that some of Go's internal
libraries are not using the address sanitizer hooks.  The memory will
be freed, and even it weren't, a few small space leaks could not cause
a segmentation violation.


> I reduced the code which can reproduce these to the three attached files. 
> With this reduced code I can see the failures
> a lot less often though. Sometimes I can see the error quite quickly, but 
> sometimes I need to let the `run.sh` script run
> for more than a minute.

Thanks for the test case.  Unfortunately, I was unable to recreate the problem.

Looking at the code, it looks like the problem may be related to
exiting the program while the Go runtime is still being initialized.
I can't think of any reason why that would be a problem, but I also
can't think of anything else.  What C library are you using?  What
version?


> Do I need to call some cgo function to properly de-initialize go when exiting 
> the main function?

No.  But if I'm right that this is related to exiting while the
runtime is being initialized, then a workaround would be to call any
Go function on exit, even a Go function that does nothing.  Calling a
Go function will automatically wait until runtime initialization is
complete.


Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to