On Thu, Jul 11, 2019 at 8:45 PM Nitish Saboo <nitish.sabo...@gmail.com> wrote: > > I have the following function 'LoadPatternDB' where I am allocating memory > for a C struct.My C struct contains the callback function. > I have the function 'LoadPatternDB' that is running in multiple go > routines.I have written a C wrapper that internally uses syslog-ng methods. > While running the method 'LoadPatternDB' in syslogparser.go with multiple go > routines, I get the following error. > > *** Error in `fatal error: bin/main': double free or corruption > (fasttop)unexpected signal during runtime execution: 0x00007fd2b8588060 *** > > My queries are: > > 1)When do we get this error ?
That error is from the C memory allocator. It does not come from Go. It means that you called a C function such as malloc, calloc, or free, and the call detected memory corruption. It may be calling free twice on the same pointer, or it may be using a dangling pointer, or it may be some other memory corruption. We don't know. > 2)Is it because of not deallocating the struct memory, I am getting this > error ?But at the same time I am allocating separate memories for each of the > go routines. No. > 3)Is it because of the memory crunch on the system that can lead to this > error ? Unlikely. It is conceivable that malloc or calloc is returning NULL, and you are not checking for NULL, and that is leading to memory corruption. But that is unlikely to happen, and it is unlikely to cause this kind of error. > 4)The issues is seen with only multiple go routines.Single iteration of the > code is working fine. That sounds like a good place to start looking. > 5)Can I not call Go code and C code using multiple threads ? You can call C code from multiple goroutines, but of course the C code has to be prepared to handle it. It's no different from a C program that calls the C function from multiple threads. If you show us a small, complete, self-contained example, that does not call any other code, then we may be able to see the problem. 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVxWk5qeCyE4oFqgstSA7yp%2Bg4M8VZAyj3G%2Bo9iN3stiw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.