Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unix: segmentation fault #165

Closed
emersion opened this issue Jun 21, 2016 · 38 comments
Closed

unix: segmentation fault #165

emersion opened this issue Jun 21, 2016 · 38 comments

Comments

@emersion
Copy link
Contributor

Thread 1 "main" received signal SIGSEGV, Segmentation fault.
0x00000000010f40d0 in ?? ()
(gdb) bt
#0  0x00000000010f40d0 in ?? ()
#1  0x00000000007aacae in onConfigure (win=0x1020df0, e=0x10f0ee0, data=0x105b020) at /home/simon/projects/libui/unix/window.c:53
#2  0x00007ffff721372c in ?? () from /usr/lib/libgtk-3.so.0
#3  0x00007ffff5973fa5 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#4  0x00007ffff5985fb2 in ?? () from /usr/lib/libgobject-2.0.so.0
#5  0x00007ffff598e6bf in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#6  0x00007ffff598efff in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#7  0x00007ffff73557bc in ?? () from /usr/lib/libgtk-3.so.0
#8  0x00007ffff7212784 in gtk_main_do_event () from /usr/lib/libgtk-3.so.0
#9  0x00007ffff6d49735 in ?? () from /usr/lib/libgdk-3.so.0
#10 0x00007ffff6d766a2 in ?? () from /usr/lib/libgdk-3.so.0
#11 0x00007ffff569edd7 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#12 0x00007ffff569f040 in ?? () from /usr/lib/libglib-2.0.so.0
#13 0x00007ffff569f362 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#14 0x00007ffff7211a55 in gtk_main () from /usr/lib/libgtk-3.so.0
#15 0x00000000007a757d in uiMain () at /home/simon/projects/libui/unix/main.c:37
#16 0x0000000000469630 in runtime.asmcgocall () at /usr/lib/go/src/runtime/asm_amd64.s:582
#17 0x000000c8200216d8 in ?? ()
#18 0x000000000041017a in runtime.cgocall (fn=0xdbd100 <runtime.work+192>, arg=0x7fffffffe790, ~r2=14406048) at /usr/lib/go/src/runtime/cgocall.go:110
#19 0x000000000043df60 in runtime.startTheWorldWithSema () at /usr/lib/go/src/runtime/proc.go:986
#20 0x0000000000dbd100 in runtime.work ()
#21 0x00007fffffffe790 in ?? ()
#22 0x0000000000dbd1a0 in runtime.work ()
#23 0x000000000043dfd2 in runtime.mstart () at /usr/lib/go/src/runtime/proc.go:1068
#24 0x0000000000467a68 in runtime.rt0_go () at /usr/lib/go/src/runtime/asm_amd64.s:149
#25 0x0000000000000001 in ?? ()
#26 0x00007fffffffe8a8 in ?? ()
#27 0x0000000000000001 in ?? ()
#28 0x00007fffffffe8a8 in ?? ()
#29 0x0000000000000000 in ?? ()
@parro-it
Copy link
Contributor

parro-it commented Jun 21, 2016

Digging in the source:

static gboolean onConfigure(GtkWidget *win, GdkEvent *e, gpointer data)
{
    uiWindow *w = uiWindow(data);

    // there doesn't seem to be a way to determine if only moving or only resizing is happening :/
    if (w->changingPosition)
        w->changingPosition = FALSE;
    else
        (*(w->onPositionChanged))(w, w->onPositionChangedData);
    // always continue handling
    return FALSE;
}

I think there should be a check to verify if there is an onPositionChanged event handler before calling it (onPositionChanged:53)

@emersion
Copy link
Contributor Author

I tried to replace the else by else if (*(w->onPositionChanged) != NULL) but the segfault still happens. Am I doing the check wrong?

@emersion
Copy link
Contributor Author

Note to myself: do the same thing with onContentSizeChanged.

@parro-it
Copy link
Contributor

I tried to replace the else by else if (*(w->onPositionChanged) != NULL) but the segfault still happens. Am I doing the check wrong?

Yes, you should check it before dereferencing the pointer:

if (w->onPositionChanged != NULL)

@emersion
Copy link
Contributor Author

That what I've been trying in the first time. Just retried it, but the segfault still occurs. :(

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

p *(uiWindow*)0x105b020 (or whatever the new value of the data= parameter to onConfigure is in your newest stack trace)?

@emersion
Copy link
Contributor Author

The current code:

    if (w->changingPosition)
        w->changingPosition = FALSE;
    else if (w->onPositionChanged != NULL)
        (*(w->onPositionChanged))(w, w->onPositionChangedData);

Stack trace:

Thread 1 "main" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00000000007aaa9e in onConfigure (win=0x1020df0, e=0x10f04a0, data=0xf5dac0) at /home/simon/projects/libui/unix/window.c:53
#2  0x00007ffff721372c in ?? () from /usr/lib/libgtk-3.so.0
#3  0x00007ffff5973fa5 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#4  0x00007ffff5985fb2 in ?? () from /usr/lib/libgobject-2.0.so.0
#5  0x00007ffff598e6bf in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#6  0x00007ffff598efff in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#7  0x00007ffff73557bc in ?? () from /usr/lib/libgtk-3.so.0
#8  0x00007ffff7212784 in gtk_main_do_event () from /usr/lib/libgtk-3.so.0
#9  0x00007ffff6d49735 in ?? () from /usr/lib/libgdk-3.so.0
#10 0x00007ffff6d766a2 in ?? () from /usr/lib/libgdk-3.so.0
#11 0x00007ffff569edd7 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#12 0x00007ffff569f040 in ?? () from /usr/lib/libglib-2.0.so.0
#13 0x00007ffff569f362 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#14 0x00007ffff7211a55 in gtk_main () from /usr/lib/libgtk-3.so.0
#15 0x00000000007a736d in uiMain () at /home/simon/projects/libui/unix/main.c:37
#16 0x0000000000469630 in runtime.asmcgocall () at /usr/lib/go/src/runtime/asm_amd64.s:582
#17 0x000000c820025ed8 in ?? ()
#18 0x000000000041017a in runtime.cgocall (fn=0xdbcc00 <runtime.g0+64>, arg=0x7fffffffe790, ~r2=14404544) at /usr/lib/go/src/runtime/cgocall.go:110
#19 0x000000000043df60 in runtime.startTheWorldWithSema () at /usr/lib/go/src/runtime/proc.go:986
#20 0x0000000000dbcc00 in runtime.g0 ()
#21 0x00007fffffffe790 in ?? ()
#22 0x0000000000dbcbc0 in runtime.work ()
#23 0x000000000043dfd2 in runtime.mstart () at /usr/lib/go/src/runtime/proc.go:1068
#24 0x0000000000467a68 in runtime.rt0_go () at /usr/lib/go/src/runtime/asm_amd64.s:149
#25 0x0000000000000001 in ?? ()
#26 0x00007fffffffe8a8 in ?? ()
#27 0x0000000000000001 in ?? ()
#28 0x00007fffffffe8a8 in ?? ()
#29 0x0000000000000000 in ?? ()

@emersion
Copy link
Contributor Author

I just added a blank line before the else and for some reason now I'm getting:

Thread 1 "Desktop-Import" received signal SIGSEGV, Segmentation fault.
0x00000000007aaa9c in onConfigure (win=0x1020df0, e=0x10f2ee0, data=0x1065220) at /home/simon/projects/libui/unix/window.c:53
53      else if (w->onPositionChanged != NULL)

@parro-it
Copy link
Contributor

@emersion: this doesn't make sense to me: sorry for the silly question ,but are you sure you have recompiled?

@emersion
Copy link
Contributor Author

Okay, just ran make clean and everything worked as expected. I'm just getting errors from #164 now.

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

This is why I want to make libui ABI-stable.

@emersion
Copy link
Contributor Author

So finally else if (w->onPositionChanged != NULL) doesn't work. Still the same error. Even if I don't call uiWindowOnPositionChanged, the condition if (w->onPositionChanged != NULL) is true.

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

This might be related to the memory corruption issue; when stack traces act like that that's usually the case. I'd still like to see the uiWindow internal structure. Can you run a backtrace and then keep the gdb session open?

@emersion
Copy link
Contributor Author

emersion commented Jun 21, 2016

Sure, ready :)

Thread 1 "main" received signal SIGSEGV, Segmentation fault.
0x0000000001125b50 in ?? ()
(gdb) bt
#0  0x0000000001125b50 in ?? ()
#1  0x00000000007aaaae in onConfigure (win=0x1020df0, e=0x10c0c10, data=0x108ce20) at /home/simon/projects/libui/unix/window.c:55
#2  0x00007ffff721372c in ?? () from /usr/lib/libgtk-3.so.0
#3  0x00007ffff5973fa5 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#4  0x00007ffff5985fb2 in ?? () from /usr/lib/libgobject-2.0.so.0
#5  0x00007ffff598e6bf in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#6  0x00007ffff598efff in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#7  0x00007ffff73557bc in ?? () from /usr/lib/libgtk-3.so.0
#8  0x00007ffff7212784 in gtk_main_do_event () from /usr/lib/libgtk-3.so.0
#9  0x00007ffff6d49735 in ?? () from /usr/lib/libgdk-3.so.0
#10 0x00007ffff6d766a2 in ?? () from /usr/lib/libgdk-3.so.0
#11 0x00007ffff569edd7 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#12 0x00007ffff569f040 in ?? () from /usr/lib/libglib-2.0.so.0
#13 0x00007ffff569f362 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#14 0x00007ffff7211a55 in gtk_main () from /usr/lib/libgtk-3.so.0
#15 0x00000000007a736d in uiMain () at /home/simon/projects/libui/unix/main.c:37
#16 0x0000000000469630 in runtime.asmcgocall () at /usr/lib/go/src/runtime/asm_amd64.s:582
#17 0x000000c820027ed8 in ?? ()
#18 0x000000000041017a in runtime.cgocall (fn=0xdbcc00 <runtime.g0+64>, arg=0x7fffffffe1f0, ~r2=14404544) at /usr/lib/go/src/runtime/cgocall.go:110
#19 0x000000000043df60 in runtime.startTheWorldWithSema () at /usr/lib/go/src/runtime/proc.go:986
#20 0x0000000000dbcc00 in runtime.g0 ()
#21 0x00007fffffffe1f0 in ?? ()
#22 0x0000000000dbcbc0 in runtime.work ()
#23 0x000000000043dfd2 in runtime.mstart () at /usr/lib/go/src/runtime/proc.go:1068
#24 0x0000000000467a68 in runtime.rt0_go () at /usr/lib/go/src/runtime/asm_amd64.s:149
#25 0x0000000000000001 in ?? ()
#26 0x00007fffffffe308 in ?? ()
#27 0x0000000000000001 in ?? ()
#28 0x00007fffffffe308 in ?? ()
#29 0x0000000000000000 in ?? ()

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

What do you get with

p *(uiWindow*)0x108ce20

@emersion
Copy link
Contributor Author

(gdb) p *(uiWindow*)0x108ce20
A syntax error in expression, near `)0x108ce20'.

Sorry, I really don't know how to use gdb.

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

Ah, it's print, not p.

@emersion
Copy link
Contributor Author

emersion commented Jun 21, 2016

(gdb) print *(uiWindow*)0x108ce20
A syntax error in expression, near `)0x108ce20'.
(gdb) print (uiWindow)*0x108ce20
Cannot look up value of a typedef `uiWindow'.

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

Ugh why is that complaining :| print *((struct uiWindow *)0x108ce20)?

@emersion
Copy link
Contributor Author

emersion commented Jun 21, 2016

(gdb) print *((struct uiWindow *)0x108ce20)
A syntax error in expression, near `struct uiWindow *)0x108ce20)'.

(thinking of you @parro-it getting plenty of email notifications)

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

What does show language say?

@emersion
Copy link
Contributor Author

(gdb) show language
The current source language is "auto; currently go".

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

Ah! That would be why the print is failing then. Try the print again after set language c?

@emersion
Copy link
Contributor Author

Ah! You were right:

(gdb) set language c
(gdb) p *(uiWindow*)0x108ce20
$3 = {c = {c = {Signature = 1018, OSSignature = 0, TypeSignature = 65, Destroy = 0x2, Handle = 0xe32c00, Parent = 0xee8f11, SetParent = 0x0, Toplevel = 0x100000080, 
      Visible = 0x0, Show = 0x3fa, Hide = 0x41, Enabled = 0x1, Enable = 0x10a3600, Disable = 0x7ffff73eac1c}, parent = 0x0, addedBefore = 128, SetContainer = 0x0}, 
  widget = 0x0, container = 0x91, window = 0x10fe2f0, vboxWidget = 0x10958f0, vboxContainer = 0x0, vbox = 0xe8e4d0, childHolderWidget = 0x0, childHolderContainer = 0x0, 
  menubar = 0x1070d90, child = 0x0, margined = 17980208, onClosing = 0x10fc980, onClosingData = 0x0, onPositionChanged = 0x1125b50, onPositionChangedData = 0xf54dd0, 
  changingPosition = 0, onContentSizeChanged = 0x0, onContentSizeChangedData = 0x0, changingSize = 144, fullscreen = 0}

@emersion
Copy link
Contributor Author

uiWindowOnPositionChanged(w, defaultOnPositionContentSizeChanged, NULL);

Are you missing a * here?

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

No. Something else is corrupting _all of_ w. This is related to that other issue you filed.

Just to be safe, print defaultOnPositionContentSizeChanged to show that the values there are actually corrupt.

@emersion
Copy link
Contributor Author

This doesn't happen all the time. I would say 60% segfault, 30% the other issue, 10% runs properly.

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

Yes, that makes it even stranger.

Try this: in window.c, after the uiUnixNewControl() call, add a g_print("w = %p",w);G_BREAKPOINT();. When the breakpoint fires, take the address of w that's printed and add a watchpoint to its Signature member, and we'll see when it gets clobbered.

@emersion
Copy link
Contributor Author

(gdb) watch ((uiWindow*)0xeb6830)->Signature
There is no member named Signature.

Where is Signature coming from?

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

((uiControl*) not ((uiWindow*)

@emersion
Copy link
Contributor Author

The value is modified twice: I open a first window, then another one, and after that I close the first one.

(gdb) run
Starting program: /home/simon/go/src/github.com/ProtonMail/xxx/xxx 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7fffeca6f700 (LWP 11164)]
[New Thread 0x7fffec26e700 (LWP 11165)]
[New Thread 0x7fffeba6d700 (LWP 11166)]
[New Thread 0x7fffeb26c700 (LWP 11167)]
[New Thread 0x7fffea463700 (LWP 11168)]
[New Thread 0x7fffe9c62700 (LWP 11169)]
w = 0xeb6830
Thread 1 "xxx" received signal SIGTRAP, Trace/breakpoint trap.
uiNewWindow (title=0xdf2110 "ProtonMail xxx Tool", width=300, height=100, hasMenubar=0) at /home/simon/projects/libui/unix/window.c:291
291     w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
(gdb) watch ((uiControl*)0xeb6830)->Signature
Hardware watchpoint 1: ((uiControl*)0xeb6830)->Signature
(gdb) continue
Continuing.
[New Thread 0x7fffdbfff700 (LWP 11175)]
w = 0xf13510
Thread 1 "xxx" received signal SIGTRAP, Trace/breakpoint trap.
uiNewWindow (title=0xfe2320 "Loading...", width=300, height=50, hasMenubar=0) at /home/simon/projects/libui/unix/window.c:291
291     w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
(gdb) continue
Continuing.
2016/06/21 17:08:37 PROGRESS: &{Logging in to ProtonMail... -1}
[New Thread 0x7fffdb7fe700 (LWP 11176)]
2016/06/21 17:08:38 PROGRESS: &{Unlocking ProtonMail mailbox... -1}
w = 0xfd86a0
Thread 1 "xxx" received signal SIGTRAP, Trace/breakpoint trap.
uiNewWindow (title=0xf9edd0 "ProtonMail xxx Tool", width=300, height=100, hasMenubar=0) at /home/simon/projects/libui/unix/window.c:291
291     w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
(gdb) continue
Continuing.
[Thread 0x7fffdbfff700 (LWP 11175) exited]
[New Thread 0x7fffdbfff700 (LWP 11188)]

Thread 1 "xxx" received signal SIGSEGV, Segmentation fault.
0x0000000000ebcee0 in ?? ()
(gdb) bt
#0  0x0000000000ebcee0 in ?? ()
#1  0x00000000007aaade in onConfigure (win=0x1020df0, e=0xfbc3f0, data=0xf13510) at /home/simon/projects/libui/unix/window.c:53
#2  0x00007ffff721372c in ?? () from /usr/lib/libgtk-3.so.0
#3  0x00007ffff5973fa5 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#4  0x00007ffff5985fb2 in ?? () from /usr/lib/libgobject-2.0.so.0
#5  0x00007ffff598e6bf in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#6  0x00007ffff598efff in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#7  0x00007ffff73557bc in ?? () from /usr/lib/libgtk-3.so.0
#8  0x00007ffff7212784 in gtk_main_do_event () from /usr/lib/libgtk-3.so.0
#9  0x00007ffff6d49735 in ?? () from /usr/lib/libgdk-3.so.0
#10 0x00007ffff6d766a2 in ?? () from /usr/lib/libgdk-3.so.0
#11 0x00007ffff569edd7 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#12 0x00007ffff569f040 in ?? () from /usr/lib/libglib-2.0.so.0
#13 0x00007ffff569f362 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#14 0x00007ffff7211a55 in gtk_main () from /usr/lib/libgtk-3.so.0
#15 0x00000000007a73ad in uiMain () at /home/simon/projects/libui/unix/main.c:37
#16 0x0000000000469670 in runtime.asmcgocall () at /usr/lib/go/src/runtime/asm_amd64.s:582
#17 0x000000c820027ed8 in ?? ()
#18 0x00000000004101ba in runtime.cgocall (fn=0xdbcc00 <runtime.g0+64>, arg=0x7fffffffe1f0, ~r2=14404544) at /usr/lib/go/src/runtime/cgocall.go:110
#19 0x000000000043dfa0 in runtime.startTheWorldWithSema () at /usr/lib/go/src/runtime/proc.go:986
#20 0x0000000000dbcc00 in runtime.g0 ()
#21 0x00007fffffffe1f0 in ?? ()
#22 0x0000000000dbcbc0 in runtime.work ()
#23 0x000000000043e012 in runtime.mstart () at /usr/lib/go/src/runtime/proc.go:1068
#24 0x0000000000467aa8 in runtime.rt0_go () at /usr/lib/go/src/runtime/asm_amd64.s:149
#25 0x0000000000000001 in ?? ()
#26 0x00007fffffffe308 in ?? ()
#27 0x0000000000000001 in ?? ()
#28 0x00007fffffffe308 in ?? ()
#29 0x0000000000000000 in ?? ()

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

At each watchpoint, can you print the value of the signature?

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

Actually scratch that; I see the watchpoint is never firing :S

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

Er wait no, I took a closer look — it's your Loading... window that's causing the problem. I wonder if it's firing a configure-event after the window has been destroyed.

Add the same line of code from earlier to uiWindowDestroy() (keeping the original one too) and try again.

@emersion
Copy link
Contributor Author

emersion commented Jun 21, 2016

Seems that's what happening. I added some g_print() in onConfigure and uiWindowDestroy and here is the output:

(gdb) run
Starting program: /home/simon/go/src/github.com/ProtonMail/xxx/xxx 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7fffeca6f700 (LWP 13268)]
[New Thread 0x7fffec26e700 (LWP 13269)]
[New Thread 0x7fffeba6d700 (LWP 13270)]
[New Thread 0x7fffeac64700 (LWP 13271)]
[New Thread 0x7fffea463700 (LWP 13272)]
[New Thread 0x7fffe8be9700 (LWP 13273)]
configure 0xed5c90
configure 0xed5c90
[New Thread 0x7fffdbfff700 (LWP 13274)]
[New Thread 0x7fffdb7fe700 (LWP 13275)]
2016/06/21 17:53:38 PROGRESS: &{Logging in to ProtonMail... -1}
configure 0x108cc10
configure 0x108cc10
[New Thread 0x7fffdaffd700 (LWP 13278)]
2016/06/21 17:53:39 PROGRESS: &{Unlocking ProtonMail mailbox... -1}
destroy 0x108cc10
configure 0xed5c90
configure 0xf4bac0
configure 0xf4bac0
configure 0x108cc10

Thread 1 "xxx" received signal SIGSEGV, Segmentation fault.
0x00007ffff51187a0 in __memset_sse2 () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff51187a0 in __memset_sse2 () from /usr/lib/libc.so.6
#1  0x00007ffff510fdda in calloc () from /usr/lib/libc.so.6
#2  0x00007ffff56a4441 in g_malloc0 () from /usr/lib/libglib-2.0.so.0
#3  0x00007ffff59801e0 in g_param_spec_pool_list () from /usr/lib/libgobject-2.0.so.0
#4  0x00007ffff5978083 in ?? () from /usr/lib/libgobject-2.0.so.0
#5  0x00007ffff5991210 in ?? () from /usr/lib/libgobject-2.0.so.0
#6  0x00007ffff59945d3 in g_type_class_ref () from /usr/lib/libgobject-2.0.so.0
#7  0x00007ffff597acd8 in g_object_newv () from /usr/lib/libgobject-2.0.so.0
#8  0x00007ffff597b3f4 in g_object_new () from /usr/lib/libgobject-2.0.so.0
#9  0x00007ffff7088cde in gtk_notebook_page_accessible_new () from /usr/lib/libgtk-3.so.0
#10 0x00007ffff7088398 in ?? () from /usr/lib/libgtk-3.so.0
#11 0x00007ffff708841a in ?? () from /usr/lib/libgtk-3.so.0
#12 0x00007ffff7354a17 in ?? () from /usr/lib/libgtk-3.so.0
#13 0x00007ffff7078a7b in ?? () from /usr/lib/libgtk-3.so.0
#14 0x00007ffff6d3fa98 in ?? () from /usr/lib/libgdk-3.so.0
#15 0x00007ffff569ec8a in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#16 0x00007ffff569f040 in ?? () from /usr/lib/libglib-2.0.so.0
#17 0x00007ffff569f362 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#18 0x00007ffff7211a55 in gtk_main () from /usr/lib/libgtk-3.so.0
#19 0x00000000007a73ad in uiMain () at /home/simon/projects/libui/unix/main.c:37
#20 0x0000000000469670 in runtime.asmcgocall () at /usr/lib/go/src/runtime/asm_amd64.s:582
#21 0x000000c820027ed8 in ?? ()
#22 0x00000000004101ba in runtime.cgocall (fn=0xdbcc00 <runtime.g0+32>, arg=0x7fffffffe1f0, ~r2=14404576) at /usr/lib/go/src/runtime/cgocall.go:110
#23 0x000000000043dfa0 in runtime.startTheWorldWithSema () at /usr/lib/go/src/runtime/proc.go:986
#24 0x0000000000dbcc00 in runtime.g0 ()
#25 0x00007fffffffe1f0 in ?? ()
#26 0x0000000000dbcbe0 in runtime.work ()
#27 0x000000000043e012 in runtime.mstart () at /usr/lib/go/src/runtime/proc.go:1068
#28 0x0000000000467aa8 in runtime.rt0_go () at /usr/lib/go/src/runtime/asm_amd64.s:149
#29 0x0000000000000001 in ?? ()
#30 0x00007fffffffe308 in ?? ()
#31 0x0000000000000001 in ?? ()
#32 0x00007fffffffe308 in ?? ()
#33 0x0000000000000000 in ?? ()
(gdb) 

Any idea how to fix it?

@emersion
Copy link
Contributor Author

emersion commented Jun 21, 2016

Maybe call gtk_widget_destroy() on the window?

gtk_widget_destroy()
If the widget is a toplevel (derived from GtkWindow), it will be removed from the list of toplevels, and the reference GTK+ holds to it will be removed.

Maybe the window is still in the list of toplevels?

(ref: https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-destroy)

@emersion
Copy link
Contributor Author

I can confirm replacing g_object_unref by gtk_widget_destroy solves the segfault. I updated my PR to apply the correct patch.

@andlabs
Copy link
Owner

andlabs commented Jun 21, 2016

Refcounting on the Unix side is a mess right now. :| Thanks for spotting all this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants