x11: Fix memory leaks in clipboard event handler

XGetWindowProperty and XGetAtomName return data which must be freed by the client, and was being leaked.
This commit is contained in:
Frank Praznik
2024-11-26 10:54:59 -05:00
parent 5c8bed3780
commit bbc9c75618

View File

@@ -650,7 +650,9 @@ static void X11_HandleClipboardEvent(SDL_VideoDevice *_this, const XEvent *xeven
int allocationsize = (length + 1) * sizeof(char*);
for (j = 0, patom = (Atom*)data; j < length; j++, patom++) {
allocationsize += SDL_strlen( X11_XGetAtomName(display, *patom) ) + 1;
char *atomStr = X11_XGetAtomName(display, *patom);
allocationsize += SDL_strlen(atomStr) + 1;
X11_XFree(atomStr);
}
char **new_mime_types = SDL_AllocateTemporaryMemory(allocationsize);
@@ -658,13 +660,19 @@ static void X11_HandleClipboardEvent(SDL_VideoDevice *_this, const XEvent *xeven
char *strPtr = (char *)(new_mime_types + length + 1);
for (j = 0, patom = (Atom*)data; j < length; j++, patom++) {
char *atomStr = X11_XGetAtomName(display, *patom);
new_mime_types[j] = strPtr;
strPtr = stpcpy(strPtr, X11_XGetAtomName(display, *patom)) + 1;
strPtr = stpcpy(strPtr, atomStr) + 1;
X11_XFree(atomStr);
}
new_mime_types[length] = NULL;
SDL_SendClipboardUpdate(false, new_mime_types, length);
}
if (data) {
X11_XFree(data);
}
}
videodata->selection_waiting = false;