On Thu, Jul 11, 2019 at 11:41 PM Nitish Saboo <nitish.sabo...@gmail.com> wrote: > > syslogparser.go > ============= > > func (obj SyslogParser) LoadPatternDB(opts Syslog, workerId int) { > patterndbpath := C.CString(opts.Patterndb) . <<<<<<<<<<<<<<< . STEP 1 > defer C.free(unsafe.Pointer(patterndbpath)) . <<<<<<<<<<<<<<<< STEP 2 > InitStruct := (*C.Accumulatedparams)(C.calloc(1, > C.sizeof_struct_Accumulatedparams)) > InitStruct.callback = (C.key_value_cb)(C.callback) > InitStruct.data = C.int(workerId) > C.load_pattern_db(patterndbpath, > (*C.Accumulatedparams)(unsafe.Pointer(InitStruct)), C.int(workerId)) > } > > Since I am running this program in multiple go routines, when we do above > STEP 1 : > > 1)Will the C memory allocate different addresses for 'patterndbpath' in both > the routines ...Am I right ?
Yes. > 2)You said 'It may be calling free twice on the same pointer', but I am > assigning a different pointer in STEP 1 everytime for each routine...Am I > right ? Yes, you will see a different pointer each time you call C.calloc, and in the code that I see that pointer is only freed once, but I have no idea what the rest of your code is doing. > 3)Is it possible that one Go routine has already freed up the address that > the other Go routine is trying to free and that is causing this 'fatal > error: bin/main': double free or corruption (fasttop)' Yes, that is possible. It won't happen with the code I see above but I have no idea what the rest of your code is doing. > Is this because of the race condition between two routines that this error is > seen ? It is possible. > 4)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. > >> As you have mentioned problem is happening when we call 'C.free'.Do you > >> mean by not calling internal syslog-ng methods and just calling a normal C > >> program with multiple go routines ? > Please correct me here if I am wrong I mean any small, self-contained example where we can see all the code. You seem to be looking at a memory corruption or double free problem. These are normal, ordinary, problems when writing C code. We can't debug your problem for you. 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/CAOyqgcWQkD8QybZmcjX5EfcSzDOJLPMoOR5P99zW496eDHiAdA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.