Fix leak of copy and paste on mac
parent
662dd44587
commit
97ea17e6e9
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -64,13 +64,13 @@ void setupCocoa()
|
|||
|
||||
bool copyToPBoard(const unsigned short *str, unsigned int len)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
|
||||
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
||||
[pboard clearContents];
|
||||
|
||||
NSArray *contentsToPaste = [[NSArray alloc] initWithObjects:[NSString stringWithCharacters:str length:len], nil];
|
||||
[pool release];
|
||||
return [pboard writeObjects:contentsToPaste];
|
||||
@autoreleasepool {
|
||||
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
||||
[pboard clearContents];
|
||||
|
||||
NSArray *contentsToPaste = [[[NSArray alloc] initWithObjects:[NSString stringWithCharacters:str length:len], nil] autorelease];
|
||||
return [pboard writeObjects:contentsToPaste];
|
||||
}
|
||||
}
|
||||
|
||||
bool pasteBoardAvailable()
|
||||
|
|
@ -79,22 +79,23 @@ bool pasteBoardAvailable()
|
|||
return [[NSPasteboard generalPasteboard] canReadObjectForClasses:classArray options:[NSDictionary dictionary]];
|
||||
}
|
||||
|
||||
const unsigned short *copyFromPBoard()
|
||||
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;
|
||||
@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 str_len = [str length];
|
||||
unichar* temp = (unichar*)calloc(str_len+1, sizeof(unichar));
|
||||
[str getCharacters:temp range:NSMakeRange(0, str_len)];
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY)
|
||||
|
|
|
|||
|
|
@ -1246,8 +1246,11 @@ BOOL LLWindowMacOSX::isClipboardTextAvailable()
|
|||
}
|
||||
|
||||
BOOL LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst)
|
||||
{
|
||||
llutf16string str(copyFromPBoard());
|
||||
{
|
||||
unsigned short* pboard_data = copyFromPBoard(); // must free returned data
|
||||
llutf16string str(pboard_data);
|
||||
free(pboard_data);
|
||||
|
||||
dst = utf16str_to_wstring(str);
|
||||
if (dst != L"")
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue