Skip to content
Snippets Groups Projects
Commit ccce123c authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Fix leak on pasting from clipboard on macos

parent 5e814696
No related branches found
No related tags found
No related merge requests found
......@@ -83,7 +83,7 @@ int createNSApp(int argc, const char **argv);
void setupCocoa();
bool pasteBoardAvailable();
bool copyToPBoard(const unsigned short *str, unsigned int len);
const unsigned short *copyFromPBoard();
unsigned short *copyFromPBoard();
CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY);
short releaseImageCursor(CursorRef ref);
short setImageCursor(CursorRef ref);
......
......@@ -79,22 +79,24 @@ bool pasteBoardAvailable()
return [[NSPasteboard generalPasteboard] canReadObjectForClasses:classArray options:[NSDictionary dictionary]];
}
const unsigned short *copyFromPBoard()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
NSString *str = NULL;
BOOL ok = [pboard canReadObjectForClasses:classArray options:[NSDictionary dictionary]];
if (ok)
{
NSArray *objToPaste = [pboard readObjectsForClasses:classArray options:[NSDictionary dictionary]];
str = [objToPaste objectAtIndex:0];
}
unichar* temp = (unichar*)calloc([str length]+1, sizeof(unichar));
[str getCharacters:temp];
[pool release];
return temp;
unsigned short *copyFromPBoard()
{
@autoreleasepool {
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
NSString *str = NULL;
BOOL ok = [pboard canReadObjectForClasses:classArray options:[NSDictionary dictionary]];
if (ok)
{
NSArray *objToPaste = [pboard readObjectsForClasses:classArray options:[NSDictionary dictionary]];
str = [objToPaste objectAtIndex:0];
}
NSUInteger len = [str length];
unichar* temp = (unichar*)calloc(len+1, sizeof(unichar));
[str getCharacters:temp range:NSMakeRange(0, len)];
return temp;
}
}
CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY)
......
......@@ -1237,8 +1237,10 @@ BOOL LLWindowMacOSX::isClipboardTextAvailable()
}
BOOL LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst)
{
llutf16string str(copyFromPBoard());
{
unsigned short* temp = copyFromPBoard();
llutf16string str(temp);
free(temp);
dst = utf16str_to_wstring(str);
if (dst != L"")
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment