daemon: Fix GetCapabilities memory leak - #262
Merged
vkareh merged 1 commit intoJul 30, 2026
Merged
Conversation
g_variant_dup_strv() allocates a vector and duplicates every string. The generated completion helper copies that vector into the outgoing GVariant, leaving the duplicated input unowned. AddressSanitizer reports 360 direct bytes and 420 indirect bytes leaked after five calls. Pass the constant capability list directly to the helper instead. This avoids the temporary allocations while leaving the returned capabilities unchanged. Signed-off-by: Saverio Miroddi <saverio.pub2@gmail.com>
vkareh
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
completion helper
GVariantBuilder,GVariant, and duplicated stringvector
Real-world report
This leak was found in a real MATE desktop session after rebuilding Ubuntu's
mate-notification-daemon1.26.1 package with AddressSanitizer andUndefinedBehaviorSanitizer. A normal client call to
org.freedesktop.Notifications.GetCapabilitiesproduced a 64-byte direct leakfor the duplicated pointer vector and 72 indirect bytes for its seven strings.
I reproduced the same ownership bug on current upstream
masterusing anASan/UBSan build, Xvfb, and a private D-Bus session. Five
GetCapabilitiescalls leaked 156 bytes each: a 72-byte vector and 84 bytesacross eight strings. The isolated run produced only these two leak records:
g_variant_dup_strv()allocates both the NULL-terminated vector and eachstring. The generated completion helper marshals its input with
g_variant_new ("(^as)", return_caps), which copies the contents into theoutgoing D-Bus value and does not take ownership of the input. The duplicated
vector therefore had no owner after the helper returned.
The capability names are compile-time constants, so this change passes a
static, NULL-terminated vector directly to the helper instead.
Verification
masterwith ASan/UBSan and reproduced 780 leaked bytesacross five calls
same five calls; the
g_variant_dup_strv()leak was absentgdbus callreplies before and after; their direct diff wasempty
--enable-compile-warnings=maximumand built the patcheddaemon normally