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); ...@@ -83,7 +83,7 @@ int createNSApp(int argc, const char **argv);
void setupCocoa(); void setupCocoa();
bool pasteBoardAvailable(); bool pasteBoardAvailable();
bool copyToPBoard(const unsigned short *str, unsigned int len); 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); CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY);
short releaseImageCursor(CursorRef ref); short releaseImageCursor(CursorRef ref);
short setImageCursor(CursorRef ref); short setImageCursor(CursorRef ref);
......
...@@ -79,22 +79,24 @@ bool pasteBoardAvailable() ...@@ -79,22 +79,24 @@ bool pasteBoardAvailable()
return [[NSPasteboard generalPasteboard] canReadObjectForClasses:classArray options:[NSDictionary dictionary]]; return [[NSPasteboard generalPasteboard] canReadObjectForClasses:classArray options:[NSDictionary dictionary]];
} }
const unsigned short *copyFromPBoard() unsigned short *copyFromPBoard()
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; @autoreleasepool {
NSPasteboard *pboard = [NSPasteboard generalPasteboard]; NSPasteboard *pboard = [NSPasteboard generalPasteboard];
NSArray *classArray = [NSArray arrayWithObject:[NSString class]]; NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
NSString *str = NULL; NSString *str = NULL;
BOOL ok = [pboard canReadObjectForClasses:classArray options:[NSDictionary dictionary]]; BOOL ok = [pboard canReadObjectForClasses:classArray options:[NSDictionary dictionary]];
if (ok) if (ok)
{ {
NSArray *objToPaste = [pboard readObjectsForClasses:classArray options:[NSDictionary dictionary]]; NSArray *objToPaste = [pboard readObjectsForClasses:classArray options:[NSDictionary dictionary]];
str = [objToPaste objectAtIndex:0]; str = [objToPaste objectAtIndex:0];
} }
unichar* temp = (unichar*)calloc([str length]+1, sizeof(unichar)); NSUInteger len = [str length];
[str getCharacters:temp]; unichar* temp = (unichar*)calloc(len+1, sizeof(unichar));
[pool release]; [str getCharacters:temp range:NSMakeRange(0, len)];
return temp;
return temp;
}
} }
CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY) CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY)
......
...@@ -1237,8 +1237,10 @@ BOOL LLWindowMacOSX::isClipboardTextAvailable() ...@@ -1237,8 +1237,10 @@ BOOL LLWindowMacOSX::isClipboardTextAvailable()
} }
BOOL LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst) BOOL LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst)
{ {
llutf16string str(copyFromPBoard()); unsigned short* temp = copyFromPBoard();
llutf16string str(temp);
free(temp);
dst = utf16str_to_wstring(str); dst = utf16str_to_wstring(str);
if (dst != L"") 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