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 650606 - memory leaks
memory leaks
Status: RESOLVED FIXED
Product: libgnome-keyring
Classification: Core
Component: General
unspecified
Other Linux
: Normal normal
: ---
Assigned To: GNOME keyring maintainer(s)
GNOME keyring maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2011-05-19 16:18 UTC by landijk-user
Modified: 2019-02-22 11:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to fix both leaks (3.38 KB, patch)
2011-05-19 16:45 UTC, landijk-user
committed Details | Review
fix additional related issue in find_unlocked_1_reply (1.93 KB, patch)
2011-05-19 17:01 UTC, landijk-user
rejected Details | Review
Patch which fixes free() 'invalid pointer' (62.44 KB, patch)
2011-05-23 04:54 UTC, Stef Walter
none Details | Review
The right patch (863 bytes, patch)
2011-05-23 07:25 UTC, Stef Walter
none Details | Review
Updated patch after seeing backtrace (1.40 KB, patch)
2011-05-23 10:21 UTC, Stef Walter
none Details | Review

Description landijk-user 2011-05-19 16:18:36 UTC
These leaks are in the same program file. Perhaps they should be tracked as one bug.

https://bugs.launchpad.net/ubuntu/+source/libgnome-keyring/+bug/784369

https://bugs.launchpad.net/ubuntu/+source/libgnome-keyring/+bug/784788
Comment 1 landijk-user 2011-05-19 16:45:32 UTC
Created attachment 188145 [details] [review]
patch to fix both leaks

* Eliminate early outs from find_items_1_reply

* callers of make_attribute_list_va clean up attributes list
Comment 2 landijk-user 2011-05-19 17:01:46 UTC
Created attachment 188150 [details] [review]
fix additional related issue in find_unlocked_1_reply

* eliminate early outs from find_unlocked_1_reply
Comment 3 Stef Walter 2011-05-22 11:29:17 UTC
Thanks for catching those leaks. I committed a slightly different version of the patch to the gnome-3-0 branch. I made the patch simpler since I'd like to include this in the 3.0.2 release, and this is a stable branch. So a goal is having the changes be easier to verify.

In addition, the second patch seems to be unnecessary. Please correct me if I'm wrong.

http://git.gnome.org/browse/libgnome-keyring/commit/?h=gnome-3-0&id=b49e32b32d4d7c326c3bd7dd44ca1c35944a94c4
Comment 4 landijk-user 2011-05-22 15:09:41 UTC
> the second patch seems to be unnecessary.

I guess you are not convinced by my argument that it dbus_message_get_args could end up allocating something in the case when it returns an error. It looks to me like the underlying implementation in _dbus_message_iter_get_args_valist iterates over the va_list, allocating something to each argument one at a time.

If there is an error processing one of the arguments, the function jumps out of the iteration over the va_list without cleaning up anything that was allocated for the prior arguments.

So I think you have to set each argument to NULL before the call and then make sure you free each one even if there was an error. I don't see any other way to ensure they get cleaned up properly, and I don't think you can call this a bug dbus_message_get_args, because the documentation doesn't promise anything about what happens in the error case.

For reference, the version of the dbus message code I'm looking at is here:

http://cgit.freedesktop.org/dbus/dbus/tree/dbus/dbus-message.c
Comment 5 Ionut Biru 2011-05-23 02:20:21 UTC
@Stef, commit b49e32b32d4d7c326c3bd7dd44ca1c35944a94c4 crashes nm-connection-editor.

https://bugs.archlinux.org/task/24392?getfile=6936
Comment 6 Stef Walter 2011-05-23 04:54:22 UTC
Created attachment 188357 [details] [review]
Patch which fixes free() 'invalid pointer'

Ionut: Does this patch fix the problem in nm-connection-editor?
Comment 7 Stef Walter 2011-05-23 04:56:32 UTC
(In reply to comment #4)
> I guess you are not convinced by my argument that it dbus_message_get_args
> could end up allocating something in the case when it returns an error. It
> looks to me like the underlying implementation in
> _dbus_message_iter_get_args_valist iterates over the va_list, allocating
> something to each argument one at a time.

landijk-user@yahoo.com: Functions should not allocate out parameters if they return an error. Obviously there are corner cases where this is not the case (such as precondition failures). If libdbus is incorrectly returning allocated memory when dbus_message_get_args returns an error, then you should file a bug with libdbus.
Comment 8 Stef Walter 2011-05-23 07:25:34 UTC
Created attachment 188358 [details] [review]
The right patch

Sorry, uploaded the wrong patch last time. This should fix the invalid free.
Comment 9 Ionut Biru 2011-05-23 08:59:55 UTC
still crashes.
backtrace https://bugs.archlinux.org/task/24392#comment77434
Comment 10 Stef Walter 2011-05-23 10:21:54 UTC
Created attachment 188366 [details] [review]
Updated patch after seeing backtrace
Comment 11 Jan Alexander Steffens (heftig) 2011-05-23 11:18:08 UTC
Seems to be resolved with this patch.
Comment 12 Stef Walter 2011-05-23 12:28:07 UTC
Martin Pitt fixed the problem in bug #650840.
Comment 13 landijk-user 2011-05-23 16:13:39 UTC
Regarding the error case for dbus_message_get_args, a bug was filed more than two years ago.

https://bugs.freedesktop.org/show_bug.cgi?id=21259
Comment 14 Stef Walter 2011-05-23 18:01:00 UTC
(In reply to comment #13)
> Regarding the error case for dbus_message_get_args, a bug was filed more than
> two years ago.

Hmmm, yes. If it interests you, that would be a good place to post a patch fixing the problem.