| Summary: | Memory loss in clipboard_testClipboardTextFunctions | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Nitz <nitin.j4> |
| Component: | *don't know* | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | critical | ||
| Priority: | P2 | CC: | philipp.wiesemann |
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: |
Patch for memory loss
New Patch is attached |
||
The first SDL_free() added by the patch might crash if the clipboard is empty (because the variable charResult will contain its undefined default value then). No it will not crash in this case also because
anyways it will create memory on heap by using SDL_strdup("");
So to free the memory on heap we have to do SDL_free() here
otherwise memory will get lost.
If you want more security then you can add SDLTest_AssertCheck here.
But according to me no need of it :)
If the first SDL_free() added by the patch would be inside the brackets above, it would crash (because there a value is set to charResult). Otherwise it is possible that it only contains undefined data. Created attachment 2160 [details]
New Patch is attached
I attached new patch according to your concern.
If you refer clipboard_testGetClipboardText(void *arg) function in same file,
It is handling the charResult same as the patch attached.
int
clipboard_testGetClipboardText(void *arg)
{
char *charResult;
charResult = SDL_GetClipboardText();
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
SDL_free(charResult);
return TEST_COMPLETED;
}
I have also read the description of SDL_GetClipboardText on SDL Wiki
and there it is written that:
Use SDL_GetClipboardText function to get UTF-8 text from the clipboard, which must be freed with SDL_free().
Thanks!!!
Fixed, thanks! https://hg.libsdl.org/SDL/rev/062bfde7330a |
Created attachment 2158 [details] Patch for memory loss In File testautomation_clipboard.c under funciton int clipboard_testClipboardTextFunctions(void *arg) charResult = SDL_GetClipboardText(); here charResult memory definitely getting lost at two places. Patch is attached for solution Regards, Nitin