Skip to content

Commit

Permalink
fix minor leak and avoid inefficient memory reallocation with long pr…
Browse files Browse the repository at this point in the history
…operties.
  • Loading branch information
rfm committed Feb 25, 2024
1 parent d8c0593 commit 0a32e72
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions Tools/xpbs.m
Expand Up @@ -720,7 +720,6 @@ - (void) pasteboard: (NSPasteboard*)pb provideDataForType: (NSString*)type
}
else if ([type isEqual: NSFilenamesPboardType])
{

[self requestData: XG_FILE_NAME];
}
else if ([type isEqual: NSRTFPboardType])
Expand Down Expand Up @@ -942,26 +941,29 @@ - (NSMutableData*) getSelectionData: (XSelectionEvent*)xEvent

if (md == nil)
{
md = [[NSMutableData alloc] initWithBytes: (void *)data
length: count];
/* data buffer needs to be big enough for the whole property
*/
md = [[NSMutableData alloc]
initWithCapacity: count + bytes_remaining];
req_type = actual_type;
}
else
{
if (req_type != actual_type)
{
char *req_name = XGetAtomName(xDisplay, req_type);
char *act_name = XGetAtomName(xDisplay, actual_type);
NSLog(@"Selection changed type from %s to %s.",
req_name, act_name);
XFree(req_name);
XFree(act_name);
RELEASE(md);
return nil;
}
[md appendBytes: (void *)data length: count];
else if (req_type != actual_type)
{
char *req_name = XGetAtomName(xDisplay, req_type);
char *act_name = XGetAtomName(xDisplay, actual_type);
NSLog(@"Selection changed type from %s to %s.",
req_name, act_name);
XFree(req_name);
XFree(act_name);
RELEASE(md);
if (data)
{
XFree(data);
}
return nil;
}
[md appendBytes: (void *)data length: count];

long_offset += count / 4;
if (data)
Expand Down

0 comments on commit 0a32e72

Please sign in to comment.