Merge pull request #14 from javigafe/patch-1

Fix memory issues
This commit is contained in:
nonpop 2020-09-09 11:22:34 +03:00 committed by GitHub
commit 9f9a4fd80b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -36,6 +36,7 @@ XKeyboard::XKeyboard()
int reasonReturn; int reasonReturn;
_display = XkbOpenDisplay(displayName, &eventCode, &errorReturn, &major, _display = XkbOpenDisplay(displayName, &eventCode, &errorReturn, &major,
&minor, &reasonReturn); &minor, &reasonReturn);
free(displayName);
switch (reasonReturn) { switch (reasonReturn) {
case XkbOD_BadLibraryVersion: case XkbOD_BadLibraryVersion:
throw X11Exception("Bad XKB library version."); throw X11Exception("Bad XKB library version.");
@ -91,6 +92,10 @@ Bool XKeyboard::initializeXkb()
if (kbdDescPtr->names == NULL) { if (kbdDescPtr->names == NULL) {
std::cerr << "Failed to get keyboard description." << std::endl; std::cerr << "Failed to get keyboard description." << std::endl;
XFree(kbdDescPtr);
XkbFreeControls(kbdDescPtr, XkbAllControlsMask, true);
XkbFreeNames(kbdDescPtr, XkbSymbolsNameMask, true);
XkbFreeNames(kbdDescPtr, XkbGroupNamesMask, true);
return False; return False;
} }
@ -141,9 +146,17 @@ Bool XKeyboard::initializeXkb()
symName = symNameC; symName = symNameC;
XFree(symNameC); XFree(symNameC);
if (symName.empty()) { if (symName.empty()) {
XFree(kbdDescPtr);
XkbFreeControls(kbdDescPtr, XkbAllControlsMask, true);
XkbFreeNames(kbdDescPtr, XkbSymbolsNameMask, true);
XkbFreeNames(kbdDescPtr, XkbGroupNamesMask, true);
return False; return False;
} }
} else { } else {
XFree(kbdDescPtr);
XkbFreeControls(kbdDescPtr, XkbAllControlsMask, true);
XkbFreeNames(kbdDescPtr, XkbSymbolsNameMask, true);
XkbFreeNames(kbdDescPtr, XkbGroupNamesMask, true);
return False; return False;
} }
@ -190,6 +203,10 @@ Bool XKeyboard::initializeXkb()
XkbStateRec xkbState; XkbStateRec xkbState;
XkbGetState(_display, _deviceId, &xkbState); XkbGetState(_display, _deviceId, &xkbState);
_currentGroupNum = xkbState.group; _currentGroupNum = xkbState.group;
XFree(kbdDescPtr);
XkbFreeControls(kbdDescPtr, XkbAllControlsMask, true);
XkbFreeNames(kbdDescPtr, XkbSymbolsNameMask, true);
XkbFreeNames(kbdDescPtr, XkbGroupNamesMask, true);
return True; return True;
} }