After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 794360 - (SIGSEGV) Deleting an account that contains subaccounts causes a segmentation fault
(SIGSEGV) Deleting an account that contains subaccounts causes a segmentation...
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: General
2.6.19
Other Linux
: Normal normal
: ---
Assigned To: gnucash-general-maint
gnucash-general-maint
Depends on:
Blocks:
 
 
Reported: 2018-03-15 13:47 UTC by mxovd
Modified: 2018-06-30 00:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
output of gnucash-valgrind (899.39 KB, text/plain)
2018-03-20 09:50 UTC, mxovd
Details
GDB output with debug symbols for GTK3 - GLIB2 and GNUCASH 2.7.7 (16.93 KB, text/plain)
2018-03-21 12:31 UTC, mxovd
Details
GDB account_tree_cmd_delete_account - line 1433-1435 (16.55 KB, application/octet-stream)
2018-03-22 03:51 UTC, mxovd
Details
GDB account_tree_cmd_delete_account - line 1433-1435 (16.55 KB, text/plain)
2018-03-22 03:53 UTC, mxovd
Details

Description mxovd 2018-03-15 13:47:31 UTC
archlinux 64bit 4.15.6-1-ARCH
gnucash 2.6.19-2 and gnucash-git 2.7.4-1

Segmentation fault when deleting an account that contains multiple accounts.
With the default accounts, deleting "Auto" triggers it
This error happened on both of my arch machines with 2.6 and 2.7

Stacktrace:

Thread 1 "gnucash" received signal SIGSEGV, Segmentation fault.
0x00007ffff650c0d6 in gtk_widget_is_sensitive ()
   from /usr/lib/libgtk-x11-2.0.so.0

Thread 1 "gnucash" received signal SIGSEGV, Segmentation fault.
0x00007ffff650c0d6 in gtk_widget_is_sensitive () from /usr/lib/libgtk-x11-2.0.so.0
(gdb) bt full
  • #0 gtk_widget_is_sensitive
  • #1 gnc_plugin_page_account_tree_cmd_delete_account
    at gnc-plugin-page-account-tree.c line 1314
  • #2 g_closure_invoke
  • #3 0x00007ffff25a3b50 in
  • #4 g_signal_emit_valist
  • #5 g_signal_emit
  • #6 0x00007ffff632f884 in
  • #7 g_closure_invoke
  • #8 0x00007ffff25a3c28 in
  • #9 g_signal_emit_valist
  • #10 g_signal_emit
  • #11 gtk_widget_activate
  • #12 gtk_menu_shell_activate_item
  • #13 0x00007ffff6403140 in
  • #14 0x00007ffff63f07cc in
  • #15 g_closure_invoke
  • #16 0x00007ffff25a35aa in
  • #19 0x00007ffff650b235 in
  • #20 gtk_propagate_event
  • #21 gtk_main_do_event
  • #22 0x00007ffff40c6d5e in
  • #23 g_main_context_dispatch
  • #24 0x00007ffff5ff8081 in
  • #25 g_main_loop_run
  • #26 gtk_main
  • #27 gnc_ui_start_event_loop
    at gnc-gnome-utils.c line 622
  • #28 inner_main
    at gnucash-bin.c line 671
  • #29 0x00007ffff6980b5d in
  • #30 0x00007ffff695923a in
  • #31 0x00007ffff69f2db6 in
  • #32 scm_call_4
  • #33 0x00007ffff69599e1 in
  • #34 scm_c_with_continuation_barrier
  • #35 0x00007ffff69da21c in
  • #36 GC_call_with_stack_base
  • #37 scm_with_guile
  • #38 scm_boot_guile
  • #39 main
    at gnucash-bin.c line 826

Comment 1 John Ralls 2018-03-19 22:35:51 UTC
I'm not able to replicate this, though admittedly the bleedingest-edge distro I have is Debian Unstable.

Please debug it enough to figure out exactly what is segfaulting and why.
Comment 2 mxovd 2018-03-20 09:50:02 UTC
Created attachment 369896 [details]
output of gnucash-valgrind

G_DEBUG=gc-friendly was commented out as it prevent the crash
Comment 3 mxovd 2018-03-20 10:10:56 UTC
(In reply to mxovd from comment #2)
> Created attachment 369896 [details]
> output of gnucash-valgrind
> 
> G_DEBUG=gc-friendly was commented out as it prevent the crash

I'm not able to accurately interpret the valgrind/callgrind outputs.
There seems to be a lot of errors caused by guile and libgc
Since using G_DEBUG=gc-friendly prevent the crash, the problem might be with the gc package. I tried to downgrade it to the same version as debian unstable but the issue persists.

Do you have any pointers on where I should start looking for debugging this issue?
Comment 4 Bob 2018-03-20 10:31:24 UTC
I also had a try to replicate this but I too could not get it to fail. Could you explain the structure of the accounts involved, maybe there is a place holder or different currencies involved, do any accounts have transactions in them and which account do you delete and then the options on the dialog. Maybe easier with a screen shot.

I had a look at your valgrind output and if you do a search for "delete-account" you see this one that may be the cause...

gnc_plugin_page_account_tree_cmd_delete_account (gnc-plugin-page-account-tree.c:1467)

If you have gdb, try 'gdb gnucash' and then at the prompt 'run --g-fatal-warnings' and bt for a backtrace when it happens.

Bob
Comment 5 mxovd 2018-03-20 12:38:42 UTC
I'm using the default accounts (common) on a fresh install, with a fresh database. I just press next on every prompt. Any account containing subaccounts will trigger the crash. Once I press delete, I have to choose between deleting the subaccounts or moving them. Whatever the choice I make, once I press delete, it throws a segfault.

I ran gdb with the --g-fatal-warnings, here's the first output at the sigtrap and then at the sigsegv

Thread 1 "gnucash" received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff74f1982 in ?? () from /usr/lib/libglib-2.0.so.0
(gdb) bt
  • #0 0x00007ffff74f1982 in
  • #1 g_logv
  • #2 g_log
  • #3 gtk_distribute_natural_allocation
  • #4 0x00007ffff6dd0364 in
  • #5 0x00007ffff6cf7577 in
  • #6 0x00007ffff6dd0b5a in
  • #7 gtk_widget_size_allocate_with_baseline
  • #8 0x00007ffff6c9ed48 in
  • #9 0x00007ffff6c9f098 in
  • #10 0x00007ffff6cf7577 in
  • #11 0x00007ffff6ca0558 in
  • #12 gtk_widget_size_allocate_with_baseline
  • #13 0x00007ffff6c9ed48 in
  • #14 0x00007ffff6c9f098 in
  • #15 0x00007ffff6cf7577 in
  • #16 0x00007ffff6ca0558 in
  • #17 gtk_widget_size_allocate_with_baseline
  • #18 0x00007ffff6f307c4 in
  • #19 g_closure_invoke
  • #20 0x00007ffff65a7c28 in
  • #21 g_signal_emit_valist
  • #22 g_signal_emit
  • #23 gtk_widget_size_allocate_with_baseline
  • #24 0x00007ffff6f2ab35 in
  • #25 0x00007ffff6593ea6 in
  • #26 g_signal_emit_valist
  • #27 g_signal_emit
  • #28 0x00007ffff6cec109 in
  • #29 g_closure_invoke
  • #30 0x00007ffff65a7b50 in
  • #31 g_signal_emit_valist
  • #32 g_signal_emit
  • #33 0x00007ffff42f328f in
  • #34 0x00007ffff42ddac3 in
  • #35 0x00007ffff74ec783 in
  • #36 g_main_context_dispatch
  • #37 0x00007ffff74ec081 in
  • #38 g_main_loop_run
  • #39 gtk_main
  • #40 gnc_ui_start_event_loop
    at /tmp/trizen-outofplace/gnucash-git/src/gnucash-git/gnucash/gnome-utils/gnc-gnome-utils.c line 652
  • #41 inner_main
    at /tmp/trizen-outofplace/gnucash-git/src/gnucash-git/gnucash/gnucash-bin.c line 670
  • #42 0x00007ffff78149ee in
  • #43 0x00007ffff77f55fa in
  • #44 0x00007ffff787c83d in
  • #45 scm_call_n
  • #46 0x00007ffff786d79b in
  • #47 0x00007ffff77f5c32 in
  • #48 scm_c_with_continuation_barrier
  • #49 0x00007ffff786c1dd in
  • #50 GC_call_with_stack_base
  • #51 scm_with_guile
  • #52 scm_boot_guile
  • #53 main
    at /tmp/trizen-outofplace/gnucash-git/src/gnucash-git/gnucash/gnucash-bin.c line 810
  • #0 gtk_widget_is_sensitive
  • #1 gnc_plugin_page_account_tree_cmd_delete_account
    at /tmp/trizen-outofplace/gnucash-git/src/gnucash-git/gnucash/gnome/gnc-plugin-page-account-tree.c line 1467
  • #2 g_closure_invoke
  • #3 0x00007ffff65a7b50 in
  • #4 g_signal_emit_valist
  • #5 g_signal_emit
  • #6 0x00007ffff6c270e4 in
  • #7 0x00007ffff6593ea6 in
  • #8 g_signal_emit_valist
  • #9 g_signal_emit
  • #10 gtk_widget_activate
  • #11 gtk_menu_shell_activate_item
  • #12 0x00007ffff6dd9259 in
  • #13 0x00007ffff6dbbe78 in
  • #14 0x00007ffff6593ea6 in
  • #15 g_signal_emit_valist
  • #16 g_signal_emit
  • #17 0x00007ffff6f0f2c5 in
  • #18 0x00007ffff6db8bdb in
  • #19 gtk_main_do_event
  • #20 0x00007ffff42e99f6 in
  • #21 0x00007ffff431c275 in
  • #22 g_main_context_dispatch
  • #23 0x00007ffff74ec081 in
  • #24 g_main_loop_run
  • #25 gtk_main
  • #26 gnc_ui_start_event_loop
    at /tmp/trizen-outofplace/gnucash-git/src/gnucash-git/gnucash/gnome-utils/gnc-gnome-utils.c line 652
  • #27 inner_main
    at /tmp/trizen-outofplace/gnucash-git/src/gnucash-git/gnucash/gnucash-bin.c line 670
  • #28 0x00007ffff78149ee in
  • #29 0x00007ffff77f55fa in
  • #30 0x00007ffff787c83d in
  • #31 scm_call_n
  • #32 0x00007ffff786d79b in
  • #33 0x00007ffff77f5c32 in
  • #34 scm_c_with_continuation_barrier
  • #35 0x00007ffff786c1dd in
  • #36 GC_call_with_stack_base
  • #37 scm_with_guile
  • #38 scm_boot_guile
  • #39 main
    at /tmp/trizen-outofplace/gnucash-git/src/gnucash-git/gnucash/gnucash-bin.c line 810

Comment 6 Bob 2018-03-20 13:50:23 UTC
What version of gtk are you using, does this happen for both xml and sqlite backends, still can not reproduce on 2.7.7
Comment 7 mxovd 2018-03-20 14:09:31 UTC
I'm using gtk3 3.22.28-1 and gtk2 2.24.32-1 arch packages
It happens for sqlite3 and xml. 
This bug is affecting all my arch installs (two on i3wm and one on gnome3) so i assume it might be distro specific since no one else seems to be affected.

Do you think that this issue could be related?: https://trac.sagemath.org/ticket/24575

Note that arch doesn't have a package for gnucash as it is using webgtk2 which is deprecated. I assume that once gnucash3 is release it will be reintegrated in the arch packages.
Comment 8 Bob 2018-03-20 14:17:17 UTC
OK, I am seeing that issue from line 1467 in the gnucash.trace file but it does not crash for me so will investigate and try to come up with a fix.
Comment 9 Bob 2018-03-20 17:16:58 UTC
I think I have found what was causing the error for me which was the sensitivity of the account selectors were being retrieved for possibly invalid widgets. I have created PR319 to fix.

Hopefully these changes will be in the next release and will fix your problem. If you can, you might like to make the changes locally to prove.

Bob
Comment 10 John Ralls 2018-03-20 18:33:37 UTC
I have some issues with the PR, comments there. What problem did you see?
Comment 11 John Ralls 2018-03-20 18:52:39 UTC
That was for Bob. 

For mxovd, valgrind and guile don't get along well at all. I once tried to make an exceptions file for it but gave up after 4 hours.

Install the debug symbols for glib and gtk and build GnuCash with -DCMAKE_BUILD_TYPE=Debug. Set a breakpoint on gnc_plugin_page_account_tree_cmd_delete_account. When you get there, set a watchpoint on &sa_trans_mas. It should get changed only once, at line 1431 in 2.7.x or line 1278 in 2.6.x. After it's assigned, do `p *sa_trans_mas` to make sure that it looks like a well-formed GtkWidget and set another watch on sa_trans_mas. Set a breakpoint on line 1463 (2.7) or 1310 (2.6) and continue. If either watch fires before it stops that will be the problem. Otherwise when it stops do `p *sa_trans_mas` again to see if it's still valid. Continue and see if it crashes. If it doesn't then we may be looking at an optimization bug.
Comment 12 mxovd 2018-03-21 12:31:50 UTC
Created attachment 369953 [details]
GDB output with debug symbols for GTK3 - GLIB2 and GNUCASH 2.7.7

I built glib2, gtk3 and gnucash with debug flags and ran gdb.
The value is changed at line 1431. I then set a watch on sa_trans_mas and a break at  1463. I let it run for 1.5-2h but it never made it to the breakpoint. I'm not sure if something is wrong or if I should have let it run longer.

I did a run with only line breakpoints, printing locals at braks and bt full at the end. I joined the output to this post.

Tell me if you need more info
Comment 13 mxovd 2018-03-21 12:45:58 UTC
I just realized that sa_trans_mas changed at 1463

output at 1432:
sa_trans_mas = 0x555555bb7f40 [GNCAccountSel]
$1 = {parent_instance = {g_type_instance = {g_class = 0x555555a4d400}, ref_count = 1, qdata = 0x2}, priv = 0x555555bb7e50}

output at 1462:
sa_trans_mas = 0x555555bb7f40
$2 = {parent_instance = {g_type_instance = {g_class = 0xaaaaaaaaaaaaaaaa}, ref_count = 2863311530, qdata = 0xaaaaaaaaaaaaaaaa},
Comment 14 John Ralls 2018-03-22 01:08:25 UTC
Comment on attachment 369953 [details]
GDB output with debug symbols for GTK3 - GLIB2 and GNUCASH 2.7.7

You didn't let it run for 1.5-2 hours. It *crashed* and you didn't notice for 2 hours.

It also hit all three breakpoints, but since they all have line numbers it seems you didn't set a watchpoint. Doesn't matter, it wasn't the sa_trans_mas that changed, it was what sa_trans_mas pointed to that changed; I think that's probably from being packed into the freed sa_trans_mas_hbox at line 1433. A watch wouldn't have caught that.

That matches my code analysis and what I explained on Bob's PR.
Comment 15 mxovd 2018-03-22 01:21:21 UTC
The run I posted wasn't the one that did not finish. 
Since setting a watch on sa_trans_mas was taking too long, I ran GDB with only line breakpoints to get to the crash.

Do you need the output of the ran that i interrupted? (im on a different machine but I can reproduce it again if needed)
Comment 16 John Ralls 2018-03-22 02:44:00 UTC
No, as I said the watchpoint wouldn't trigger because it isn't sa_trans_mas that gets deallocated, it's sa_trans_mas_hbox. It would be worthWhile to check my hypothesesis by looking at sa_trans_mas before and immediately after it's packed into sa_trans_mas_hbox to make sure that that is indeed when it shows that the parent has been freed.
Comment 17 mxovd 2018-03-22 03:51:07 UTC
Created attachment 369991 [details]
GDB account_tree_cmd_delete_account -  line 1433-1435

Ran GDB with prints before and after the line 1433

tell me if you need something else, thanks
Comment 18 mxovd 2018-03-22 03:53:01 UTC
Created attachment 369992 [details]
GDB account_tree_cmd_delete_account - line 1433-1435
Comment 19 John Ralls 2018-03-22 05:24:09 UTC
So it's not there. It's actually getting freed at line 1447, g_object_unref(G_OBJECT(builder));

Since it's in the hierarchy of a toplevel created by GtkBuilder that's contrary to the documentation. It's late and I don't want to go digging through the sources right now, so I'll speculate instead that since it's never made sensitive builder treats it specially, though I suppose it's also possible that since it's created in code and added builder expects that we should have reffed it.

With the Gtk and Glib I'm using at the moment (on a Mac) the type information is NULLed at free and that's sufficient to prevent the crash in GTK_IS_WIDGET. On your system where the freed memory is set to 0xaaaaaaaaaaaaaaaa it crashes. ISTR that was a debugging behavior in old versions of GLib, but it seems to have been removed at some point; glib now NULLs memory to help garbage-collecting tools.
Comment 20 mxovd 2018-03-22 06:59:23 UTC
That would explain why export G_DEBUG=gc-friendly prevent the crash

It seems that the reason I  have this problem is the --enable-debug flag
According to glib docs,the default is --enable-debug=minimum on stable release as --enable-debug=no is not safe.

I compiled Glib with "minimum" and "no", and both do not crash.

The PKGBUILD for glib in arch uses --enable-debug=yes since 2.54.3-1 (jan-08-2018, current version) but it was changed back to minimum for 2.56.0  (8 days ago, not released yet)

This seems to be the reason why arch is crashing but other distros aren't.
Comment 21 mxovd 2018-03-26 02:49:27 UTC
PR319 solved the issue.
https://github.com/Gnucash/gnucash/pull/319

Thank you very much!
Comment 22 John Ralls 2018-06-30 00:05:32 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=794360. Please update any external references or bookmarks.