Fix memory leaks and pointer safety issues in sysin_events.mm#1
Open
PekingSpades wants to merge 1 commit intoEigenlabs:masterfrom
Open
Fix memory leaks and pointer safety issues in sysin_events.mm#1PekingSpades wants to merge 1 commit intoEigenlabs:masterfrom
PekingSpades wants to merge 1 commit intoEigenlabs:masterfrom
Conversation
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
sysin_events/sysin_events.mmwhere Core Foundation objects created with "Create" functions were not releasedChanges
Memory Leaks Fixed
mousevent()CGEventSourceCreate()return value was passed directly to another function without being releasedCFRelease()cfilterfunc_process()CGEventCreate()return value was never releasedCFRelease(reference_event)release_button1()CGEventCreate()return value was never releasedCFRelease(reference_event)release_button2()CGEventCreate()return value was never releasedCFRelease(reference_event)Pointer Safety Issues Fixed
createStringForKey()TISCopyCurrentKeyboardInputSource()andTISGetInputSourceProperty()could return NULL, causing crash on dereferencekeyCodeForChar()CFStringCreateWithCharacters()could return NULLkeyCodeForChar()CFDictionaryGetValueIfPresent()writes a pointer-sized value (8 bytes on 64-bit), but was writing toCGKeyCodewhich isuint16_t(2 bytes), causing stack corruptionconst void *variable then cast toCGKeyCodeDocumentation References
The fixes are based on Apple's official Core Foundation documentation:
The Create Rule
Source: Memory Management Programming Guide for Core Foundation - Ownership Policy
CFDictionaryGetValueIfPresent Signature
The
valueparameter is documented as: "A pointer to memory which should be filled with the pointer-sized value if a matching key is found."Source: Apple Open Source - CF/CFDictionary.h
This means on 64-bit systems, the function writes 8 bytes. Writing to a
uint16_tvariable (2 bytes) causes stack corruption.