GnuCash
Contact   Instructions
Bug 797500 - valgrind errors
Summary: valgrind errors
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: General (show other bugs)
Version: git-maint
Hardware: PC Linux
: Normal minor
Target Milestone: ---
Assignee: general
QA Contact: general
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-15 20:04 EST by Christopher Lam
Modified: 2019-11-30 14:25 EST (History)
3 users (show)

See Also:


Attachments
valgrind output.txt (1.40 MB, text/plain)
2019-11-15 20:04 EST, Christopher Lam
no flags Details
valgrind-errors.patch (13.89 KB, patch)
2019-11-16 18:15 EST, Christopher Lam
no flags Details
valgrind output after this patch - for posterity (1.49 MB, application/gzip)
2019-11-17 10:49 EST, Christopher Lam
no flags Details
try plug biggest memory leak (2.01 KB, patch)
2019-11-30 00:25 EST, Christopher Lam
no flags Details

Description Christopher Lam 2019-11-15 20:04:27 EST
Created attachment 373450 [details]
valgrind output.txt

This bug will show current valgrind output.

* Mismatched free / delete / delete [] - relates to new/g_free pairs
* Memory leaks also shown
Comment 1 John Ralls 2019-11-15 23:46:32 EST
The mismatched frees are all from freeing guids, which are allocated with operator new at https://github.com/Gnucash/gnucash/blob/maint/libgnucash/engine/guid.cpp#L107 and should be freed with guid_free (which calls operator delete) instead of free or g_free.

There are probably more of those that valgrind didn't pick up in your test run.
Comment 2 Christopher Lam 2019-11-16 18:15:57 EST
Created attachment 373452 [details]
valgrind-errors.patch

this seems to fix it.
Comment 3 John Ralls 2019-11-16 20:32:00 EST
Comment on attachment 373452 [details]
valgrind-errors.patch

Should do. Go ahead and push it.
Comment 4 Christopher Lam 2019-11-17 10:49:31 EST
Created attachment 373453 [details]
valgrind output after this patch - for posterity

post-commit valgrind output. no more malloc/free mismatches.

this output is much bigger because more switches were added to expose all memory leaks. the main warnings remaining are:

* Conditional jump or move depends on uninitialised value(s)
* Use of uninitialised value of size N
* Numerous memory leaks with libwebkit2gtk
* "Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s)" in pthread_create.c:479 - any relation to bug 797283 ???

A few gnc memory leaks (search "22,329" backwards from the end to find the largest ones)
* gnc_icons.c: icon_theme is never freed

etc.
Comment 5 Christopher Lam 2019-11-30 00:25:55 EST
Created attachment 373467 [details]
try plug biggest memory leak

I tried to plug the biggest memory leak. gtk_icon_theme_get_default() output is never freed/unreffed.

Applying this patch apparently works; no more leak -- this was 232,080 bytes in the above log.

But https://developer.gnome.org/gtk3/stable/GtkIconTheme.html#gtk-icon-theme-get-default section on gtk_icon_theme_get_default() states:

"Returns

A unique GtkIconTheme associated with the default screen. This icon theme is associated with the screen and can be used as long as the screen is open. Do not ref or unref it.

[transfer none]

Since: 2.4"

Conclusion: memory management is annoying!
Comment 6 John Ralls 2019-11-30 14:25:48 EST
The design for gtk_icon_theme_get_default() and gtk_icon_theme_get_for_screen() is that there's one icon theme for a GdkScreen. I'd expect that it should be created by the Gnome Window Manager when you start up on Linux but perhaps you're using a different WM so GnuCash was the first Gtk application to ask for the GtkIconTheme. Libgtk dutifully created it but intends for it to persist for the duration of the windowing session. Valgrind doesn't know that and reports it as a leak when GnuCash quit. 

If you didn't already you should install and use a Gtk suppression file. See https://wiki.gnome.org/Valgrind for more info.

Note You need to log in before you can comment on or make changes to this bug.