iup-go icon indicating copy to clipboard operation
iup-go copied to clipboard

Example "thread": SIGABRT crash on Close

Open justinfx opened this issue 3 years ago • 2 comments

When testing the "thread" example, on an Ubuntu linux distro, I have found that closing the dialog results in a SIGABRT when iup.Close is called.

double free or corruption (out)
SIGABRT: abort
PC=0x7f885e56ee87 m=0 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 1 [syscall]:
runtime.cgocall(0x4d8160, 0xc000075da8)
    /.../go/1.18.0/src/runtime/cgocall.go:157 +0x5c fp=0xc000075d80 sp=0xc000075d48 pc=0x42945c
github.com/gen2brain/iup-go/iup._Cfunc_IupClose()
    _cgo_gotypes.go:253 +0x45 fp=0xc000075da8 sp=0xc000075d80 pc=0x4ba705
github.com/gen2brain/iup-go/iup.Close()
    /.../src/ext/iup-go/iup/bind_iup.go:26 +0x17 fp=0xc000075db8 sp=0xc000075da8 pc=0x4d09d7
main.main()
    /.../src/ext/iup-go/examples/thread/thread.go:33 +0x311 fp=0xc000075f80 sp=0xc000075db8 pc=0x4d2e11
runtime.main()
    /.../go/1.18.0/src/runtime/proc.go:250 +0x212 fp=0xc000075fe0 sp=0xc000075f80 pc=0x45a132
runtime.goexit()
    /.../go/1.18.0/src/runtime/asm_amd64.s:1571 +0x1 fp=0xc000075fe8 sp=0xc000075fe0 pc=0x482d61

rax    0x0
rbx    0x7ffe8b025440
rcx    0x7f885e56ee87
rdx    0x0
rdi    0x2
rsi    0x7ffe8b0251d0
rbp    0x7ffe8b025540
rsp    0x7ffe8b0251d0
r8     0x0
r9     0x7ffe8b0251d0
r10    0x8
r11    0x246
r12    0x7ffe8b025440
r13    0x1000
r14    0x0
r15    0x30
rip    0x7f885e56ee87
rflags 0x246
cs     0x33
fs     0x0
gs     0x0

I've found that commenting out the following line prevents the crash:

	thread := iup.Thread()
	thread.SetCallback("THREAD_CB", iup.ThreadFunc(threadCb))
	//thread.SetHandle("thread")

justinfx avatar Jun 02 '22 23:06 justinfx

Yes, that is a known issue. If you comment on that line then the thread will not start at all, that is not a solution. The crash is in IupClose(), trying to free something that doesn't exist. Need to see if that happens in C.

gen2brain avatar Jun 02 '22 23:06 gen2brain

Just to add gdb output here:

free(): invalid pointer

Thread 1 "thread" received signal SIGABRT, Aborted.
0x00007ffff6da705c in ?? () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff6da705c in  () at /lib64/libc.so.6
#1  0x00007ffff6d5b792 in raise () at /lib64/libc.so.6
#2  0x00007ffff6d46449 in abort () at /lib64/libc.so.6
#3  0x00007ffff6d9b5f8 in  () at /lib64/libc.so.6
#4  0x00007ffff6db0cea in  () at /lib64/libc.so.6
#5  0x00007ffff6db24f4 in  () at /lib64/libc.so.6
#6  0x00007ffff6db4f71 in free () at /lib64/libc.so.6
#7  0x00000000004e1e9e in iClassDestroy (ih=0xb90220, ic=<optimized out>) at /_/github.com/gen2brain/iup-go/iup/external/src/iup_class.c:65
#8  iupClassObjectDestroy (ih=ih@entry=0xb90220) at /_/github.com/gen2brain/iup-go/iup/external/src/iup_class.c:187
#9  0x000000000054a5d8 in IupDestroy (ih=0xb90220) at /_/github.com/gen2brain/iup-go/iup/external/src/iup_object.c:206
#10 0x0000000000549690 in iupNamesDestroyHandles () at /_/github.com/gen2brain/iup-go/iup/external/src/iup_names.c:94
#11 0x000000000054a82f in IupClose () at /_/github.com/gen2brain/iup-go/iup/external/src/iup_open.c:108
#12 0x0000000000482ee4 in runtime.asmcgocall () at runtime/asm_amd64.s:821
#13 0x000000c00002e000 in  ()
#14 0x00007fffffffd418 in  ()
#15 0x00000000004625b8 in runtime.exitsyscallfast.func1 () at runtime/proc.go:3839
#16 0x0000000000481069 in runtime.systemstack () at runtime/asm_amd64.s:469
#17 0x0000000000485805 in runtime.newproc (fn=0x1) at <autogenerated>:1
#18 0x00000000006a2380 in runtime.g0 ()
#19 0x0000000000000001 in  ()
#20 0x0000000000480f65 in runtime.mstart () at runtime/asm_amd64.s:367
#21 0x0000000000480eef in runtime.rt0_go () at runtime/asm_amd64.s:331
#22 0x0000000000000001 in  ()
#23 0x00007fffffffd5b8 in  ()
#24 0x0000000000000000 in  ()
(gdb)

gen2brain avatar Jun 02 '22 23:06 gen2brain