mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-01-04 20:37:49 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user